-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtcon.sh
executable file
·50 lines (38 loc) · 844 Bytes
/
tcon.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash -e
child() {
pipe="$1"
while true; do
if read line <$pipe; then
if [[ "$line" == 'tcon-quit' ]]; then
exit 0
fi
echo "$line"
(eval "$line")
fi
done
}
run() {
concurrency="$1"
shift;
echo "Starting up tmux panes with a concurrency of $concurrency"
FIFO=$(mktemp)
rm $FIFO
mkfifo $FIFO
commands=$(cat -)
commands_count=$(echo "$commands" | wc -l | sed 's/ //g')
seq 1 "$concurrency" | xpanes "$@" -c "tcon child $FIFO"
count=0
echo "$commands" | while read f; do
count=$((count+1))
echo "$f" > "$FIFO"
echo "Running ${count}/${commands_count}: $f"
done
seq 1 "$concurrency" | while read f; do echo 'tcon-quit' > "$FIFO"; done;
# Lazy cleanup.
(sleep 2 && rm "$FIFO") &
}
if [[ "$1" == "child" ]]; then
child "$2"
else
run "$@"
fi