-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdjamterm
executable file
·141 lines (113 loc) · 3.44 KB
/
djamterm
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/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 of with the given tmux-id and terminal-num
running in the docker machines.
Usage: djamterm [tmux-id] [-t terminal-num]
This is the docker version of the jamterm command.
djamterm
Shows the first C terminal of the program that was last started.
djamterm -t 2
Shows the second C terminal of the program that was last started.
djamterm u-600-dev-2331-c -t 2
Shows the second C terminal of the program running under u-600-dev-2331.
djamterm u-600-dev-2331-c
Shows the first C terminal of the program running under u-600-dev-2331.
djamterm u-600-dev-2331-j
Shows the J terminal of the program running under u-600-dev-2331.
EOF
}
localtmux() {
local tmuxapp=$1
local termno=$2
$TMUX has-session -t $tmuxapp 2>/dev/null
res=$?
if [ $res == "0" ]; then
if [ -z $termno ]; then
$TMUX attach -t $tmuxapp
else
$TMUX attach -t $tmuxapp-$termno
fi
fi
}
dockertmux() {
local tmuxapp=$1
local termno=$2
appsfolder=$HOME"/__jamruns/apps"
cd $appsfolder
for jruns in */; do
if [ $jruns != "*/" ]; then
for jexs in `ls $appsfolder/$jruns`; do
dir=$appsfolder/$jruns$jexs
if [ -d $dir ] && [ -e $dir/class ]; then
local dcl=`cat $dir/class | tr -d '[:space:]'`
if [ $dcl == "docker" ]; then
if [ -e $dir/tmuxid_c ]; then
local dtm=`cat $dir/tmuxid_c | tr -d '[:space:]'`
if [ $dtm == $tmuxapp ]; then
docker exec -ti `cat $dir/dockerId` script -q -c "/usr/bin/tmux attach -t $tmuxapp-$termno" /dev/null
break
fi
fi
fi
fi
done
fi
done
}
###
# 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`
dockertmux $tmuxid 1
exit # this improves the readability of the script later - not needed!
fi
else
# Show help
if [ $1 == "-h" ] || [ $1 == "--help" ]; then
show_usage
exit # readability improver!
elif [ $1 == "-t" ]; then
if [ -e tmuxid ]; then
tmuxid=`cat tmuxid`
dockertmux $tmuxid $2
fi
exit # readability improver!
else
if [ -z $2 ]; then
txid=$1
if [ ${txid: -1} == "c" ]; then
# Connect to the docker to display the C panes
dockertmux $txid 1
else
localtmux $txid
fi
exit # readability improver!
else
if [ -n $3 ] && [ $2 == "-t" ]; then
termid=$3
dockertmux $1 $termid
fi
fi
fi
fi