-
Notifications
You must be signed in to change notification settings - Fork 0
/
jamclose
executable file
·84 lines (63 loc) · 1.47 KB
/
jamclose
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
#!/bin/bash
# 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
}
closeterm() {
local tmuxapp=$1
$TMUX has-session -t $tmuxapp 2>/dev/null
local res=$?
if [ $res == "0" ]; then
$TMUX detach-client -s $tmuxapp
fi
}
closeall() {
if [ "$(ls -A $jamfolder)" ]; then
cd $jamfolder
for jruns in */; do
if [ $jruns != "*/" ]; then
for jport in `ls $jamfolder/$jruns`; do
dir=$jamfolder/$jruns$jport
if [ -d $dir ]; then
if [ -e $dir/tmuxid ]; then
local tmuxid=`cat $dir/tmuxid`
closeterm $tmuxid
fi
fi
done
fi
done
fi
}
show_usage() {
cat << EOF
jamclose tmux-id
Closes the given terminal.
jamclose
Closes all open terminal (tmux terminals showing running JAMScript devices).
EOF
}
jamfolder=$HOME"/__jamruns"
if [ -z $1 ]; then
if [ ! -d $jamfolder ]; then
echo "No running instances of JAMScript."
exit 0
fi
closeall
exit
fi
if [ $1 == "-h" ] || [ $1 == "--help" ]; then
show_usage
exit
fi
if [ ! -d $jamfolder ]; then
echo "No running instances of JAMScript."
exit 0
fi
closeterm $1