-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtm
More file actions
executable file
·44 lines (40 loc) · 916 Bytes
/
tm
File metadata and controls
executable file
·44 lines (40 loc) · 916 Bytes
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
#!/bin/bash
# wrapper script for tmux
# attaches to session if program is running, otherwise starts program
SESSION=""
OPTS=""
while getopts dls: OPT; do
case "$OPT" in
d)
OPTS="-d"
;;
l)
tmux list-sessions 2> /dev/null
exit $?
;;
s)
SESSION="$OPTARG"
;;
?)
exit 1
;;
esac
done
shift $(( OPTIND - 1 ))
CMD=$*
if [[ -z $SESSION ]]; then
SESSION=$1
fi
if [[ -z $SESSION ]]; then
echo >&2 << EOF "usage: $(basename $0) [-l] [-d] [-s name] [cmd]
-l list tmux sessions
-d restrict session to one client
-s use name as session name instead of \$1 of cmd"
EOF
exit 1
fi
if [[ -z $(tmux list-sessions 2> /dev/null | grep "^${SESSION}:") ]]; then
tmux new-session -s $SESSION "$CMD"
else
tmux attach-session $OPTS -t $SESSION
fi