-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtmux-many
executable file
·108 lines (86 loc) · 1.71 KB
/
tmux-many
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/bin/bash
set -o errexit -o noclobber -o nounset -o pipefail
params="$(getopt -o wil: -l wait,layout:,titles: --name "$0" -- "$@")"
eval set -- "$params"
unset params
#layout="main-horizontal"
layout=""
read_stdin="false"
wait="false"
titles=""
while true
do
case "$1" in
-w|--wait)
wait="true"
shift
;;
-i)
read_stdin="true"
shift 2
;;
-l|--layout)
layout="$2"
shift 2
;;
--titles)
titles="$2"
shift 2
;;
--)
shift
break
;;
*)
echo "Not implemented: $1" >&2
exit 1
;;
esac
done
declare -a params
IFS=',' read -r -a titles <<< "$titles"
#params+=(set-option -g remain-on-exit on ';')
#params+=(set pane-border-status bottom ';' set pane-border-format "#{pane_title}" ';')
paneCount=0
function add_pane() {
local command="$1"
local action
if (( paneCount == 0 )); then
if [[ -z "${TMUX:-}" ]]; then
action="new-session"
else
action=""
exec="$command"
fi
else
action="split-window"
fi
(( ++paneCount ))
if [[ -n "$action" ]]; then
params+=($action "$command" ';')
fi
if ! [[ -z "${titles[$paneCount]-}" ]]; then
params+=(select-pane -T "${titles[$paneCount]}" ';')
fi
}
if [[ "$read_stdin" == "true" ]]; then
while ifs= read -r line; do
add_pane "$line"
done
else
# Run each parameter in separate window
while ! [[ -z "${1-}" ]]; do
add_pane "$1"
shift
done
fi
if [[ -n "$layout" ]]; then
params+=( select-layout $layout ';' )
fi
if [[ "$wait" == "true" ]]; then
params+=(set remain-on-exit on ';')
fi
tmux "${params[@]}"
if [[ -n "$exec" ]]; then
exec ${exec}
fi