equal
deleted
inserted
replaced
|
1 |
|
2 # sss |
|
3 # Reattach a GNU Screen session, or a TMux session. |
|
4 # |
|
5 # For GNU Screen a custom lock tool (LOCKPRG) can be used |
|
6 # if ~/bin/ttylocker exists or TTYLOCKER is set (not yet |
|
7 # implemented for tmux). |
|
8 # Mikael Berthe, 2015-08 |
|
9 |
|
10 function sss() { |
|
11 local TTYLOCKER="${TTYLOCKER:-$HOME/bin/ttylocker}" |
|
12 local SCREENBIN="/usr/bin/screen" |
|
13 local TMUXBIN="/usr/bin/tmux" |
|
14 |
|
15 if [[ -x $SCREENBIN ]]; then |
|
16 $SCREENBIN -q -list |
|
17 local r=$? |
|
18 if (( r == 11 )); then |
|
19 # There is 1 usable Screen session, let's go |
|
20 [[ -x "$TTYLOCKER" ]] && export LOCKPRG="$TTYLOCKER" |
|
21 exec $SCREENBIN -r -x |
|
22 elif (( r > 11 )); then |
|
23 # There are several usable Screen sessions, heh |
|
24 echo "There are several usable Screen sessions..." |
|
25 return |
|
26 fi |
|
27 fi |
|
28 |
|
29 # No usable GNU/Screen session, let's try tmux then. |
|
30 if [[ -x "$TMUXBIN" ]]; then |
|
31 # Number of tmux sessions |
|
32 integer n=$($TMUXBIN list-sessions 2>/dev/null | wc -l) |
|
33 if (( n == 1 )); then |
|
34 # Attach the session |
|
35 exec $TMUXBIN attach # -t "$($TMUXBIN list-session -F '#{session_id}')" |
|
36 elif (( n > 1 )); then |
|
37 # There are several usable tmux sessions, heh |
|
38 echo "There are several usable tmux sessions..." |
|
39 return |
|
40 fi |
|
41 fi |
|
42 |
|
43 echo "No terminal multiplexer session found." |
|
44 } |