add --color flag to set starting color offset
2 files changed,  +41, -6
M README.md
+19, -2
 1@@ -5,13 +5,30 @@ Run multiple commands with multiplexed, colorized output.
 2 ## Usage
 3 
 4 ```bash
 5-concurrently NAME1 'COMMAND1' [NAME2 'COMMAND2' ...]
 6+concurrently [--color N] NAME1 'COMMAND1' [NAME2 'COMMAND2' ...]
 7 ```
 8 
 9+### Options
10+
11+- `--color N` - Starting color offset (0-6). Useful when running multiple concurrent
12+  instances in parallel to differentiate their output colors.
13+
14 ## Example
15 
16 ```bash
17-concurrently Vite 'pnpm exec vite' Go 'find . -name "*.go" | entr go build'
18+concurrently Vite 'pnpm exec vite' Go 'find . -name "*.go" | entr go run .'
19+```
20+
21+### Multiple Instances with Different Colors
22+
23+When running multiple independent concurrent processes, use `--color` to differentiate them:
24+
25+```bash
26+# Terminal 1 - starts with cyan (color 0)
27+concurrently --color 0 Frontend 'npm run dev' Backend 'go run main.go'
28+
29+# Terminal 2 - starts with yellow (color 2)
30+concurrently --color 2 Worker 'python worker.py' Notifier 'node notify.js'
31 ```
32 
33 Output:
M concurrently
+22, -4
 1@@ -1,14 +1,30 @@
 2 #!/usr/bin/env bash
 3 #
 4 # concurrently - Run multiple commands with multiplexed output
 5-# Usage: concurrently NAME1 'COMMAND1' [NAME2 'COMMAND2' ...]
 6+# Usage: concurrently [--color N] NAME1 'COMMAND1' [NAME2 'COMMAND2' ...]
 7 #
 8 # Runs all commands in parallel with output prefixed by [NAME].
 9 # Press Ctrl+C to terminate all processes.
10 #
11+# Options:
12+#   --color N    Starting color offset (0-6), useful when running multiple
13+#                concurrent instances to differentiate output colors
14+#
15 
16 set -euo pipefail
17 
18+# Parse optional --color flag
19+COLOR_OFFSET=0
20+if [[ $# -ge 2 && "$1" == "--color" ]]; then
21+    if [[ "$2" =~ ^[0-9]+$ ]]; then
22+        COLOR_OFFSET="$2"
23+        shift 2
24+    else
25+        echo "Error: --color requires a non-negative integer" >&2
26+        exit 1
27+    fi
28+fi
29+
30 # Color palette for dark terminal themes
31 # Format: \e[38;2;R;G;Bm (256-color true color)
32 declare -a COLORS=(
33@@ -28,7 +44,9 @@ EXIT_CODE=0
34 
35 # Validate we have at least one name-command pair
36 if [[ $# -lt 2 ]]; then
37-    echo "Usage: concurrently NAME1 'COMMAND1' [NAME2 'COMMAND2' ...]" >&2
38+    echo "Usage: concurrently [--color N] NAME1 'COMMAND1' [NAME2 'COMMAND2' ...]" >&2
39+    echo "  --color N    Starting color offset (0-6), useful when running multiple" >&2
40+    echo "               concurrent instances to differentiate output colors" >&2
41     exit 1
42 fi
43 
44@@ -118,8 +136,8 @@ while [[ $# -gt 0 ]]; do
45     # Create FIFO
46     mkfifo "$fifo"
47 
48-    # Assign color (modulo to cycle through palette)
49-    color_index=$((job_index % NUM_COLORS))
50+    # Assign color (modulo to cycle through palette, with optional offset)
51+    color_index=$(((COLOR_OFFSET + job_index) % NUM_COLORS))
52     color="${COLORS[$color_index]}"
53 
54     # Start reader for this FIFO with assigned color