-
Notifications
You must be signed in to change notification settings - Fork 0
/
jamterm
executable file
·97 lines (77 loc) · 1.93 KB
/
jamterm
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
#!/bin/bash
IDIR="${BASH_SOURCE%/*}"
if [[ ! -d "$IDIR" ]]; then IDIR="$PWD"; fi
source "$IDIR/inc/misc_tools.sh"
# Edit the following locations to provide the
TMUX=`which tmux`
if [ -z $TMUX ]; then
TMUX=/usr/local/bin/tmux
fi
# No need to edit below this line unless you find a bug!
die() {
printf '%s\n' "$1" >&2
exit 1
}
show_usage() {
cat << EOF
Shows the background terminals with the given tmux-id and terminal-num.
Usage: jamterm [tmux-id] [-t terminal-num]
jamterm
Shows the first C terminal of the program that was last started.
jamterm -t 2
jamterm u-600-dev-2331 -t 2
Shows the second C terminal of the program running under u-600-dev-2331.
jamterm u-600-dev-2331
Shows the first C terminal of the program running under u-600-dev-2331.
EOF
}
localtmux() {
local tmuxapp=$1
local termno=$2
$TMUX has-session -t $tmuxapp-$termno 2>/dev/null
res=$?
if [ $res == "0" ]; then
if [ -z $termno ]; then
$TMUX attach -t $tmuxapp
else
$TMUX attach -t $tmuxapp-$termno
fi
fi
}
###
# Main script execution begins here...
#
jamfolder=$HOME"/__jamruns"
exit_missingdir $jamfolder "__jamruns folder missing. JAMScript tools not setup?"
appsfolder=$jamfolder/apps
exit_missingdir $appsfolder "__jamruns/apps folder missing. JAMScript tools not setup?"
cd $appsfolder
if [ -z $1 ]; then
if [ -e tmuxid ]; then
tmuxid=`cat tmuxid`
localtmux $tmuxid 1
exit
fi
else
# Show help
if [ $1 == "-h" ] || [ $1 == "--help" ]; then
show_usage
exit
elif [ $1 == "-t" ]; then
if [ -e tmuxid ]; then
tmuxid=`cat tmuxid`
localtmux $tmuxid $2
exit
fi
exit
else
if [ -z $2 ]; then
termid=1
else
if [ -n $3 ] && [ $2 == "-t" ]; then
termid=$3
fi
fi
localtmux $1 $termid
fi
fi