]> gitweb.fluxo.info Git - termplex.git/commitdiff
Support tmux and screen as fallback on root and remotes
authorSilvio Rhatto <rhatto@riseup.net>
Fri, 25 Aug 2017 11:24:02 +0000 (08:24 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Fri, 25 Aug 2017 11:24:02 +0000 (08:24 -0300)
shell

diff --git a/shell b/shell
index 31d28233723e8a3590d4e42743c4adfcc564f69b..90e3278a1deb66f6b40e5924223cc80f39f1b280 100755 (executable)
--- a/shell
+++ b/shell
@@ -13,7 +13,6 @@ DEST="$1"
 COMMAND="$2"
 #LOCAL_MULTIPLEXER="wscreen"
 LOCAL_MULTIPLEXER="wtmux"
-REMOTE_MULTIPLEXER="screen -x"
 MONITORING="-M $(($RANDOM + 1024))"
 AUTOSSH="autossh $MONITORING"
 
@@ -39,6 +38,17 @@ function shell_wtmux_ls {
   tmux ls | grep -q ^$1:
 }
 
+# Try tmux, then screen
+function shell_remote_multiplexer {
+  tmux="tmux attach"
+
+  if [ ! -z "$1" ]; then
+    tmux="$tmux -t $1"
+  fi
+
+  echo "$SUDO $tmux || $SUDO screen -x $1"
+}
+
 # Syntax check
 if [ -z "$DEST" ]; then
   exit 1
@@ -51,9 +61,10 @@ window_title $DEST
 if [ "$BASENAME" == "shells" ]; then
   # Remote screen shell using $AUTOSSH
   if [ "$COMMAND" == "root" ]; then
-    $AUTOSSH $DEST -t -- sudo $REMOTE_MULTIPLEXER
+    SUDO="sudo"
+    $AUTOSSH $DEST -t -- "`shell_remote_multiplexer`"
   else
-    $AUTOSSH $DEST -t -- $REMOTE_MULTIPLEXER $COMMAND
+    $AUTOSSH $DEST -t -- "`shell_remote_multiplexer` $COMMAND"
   fi
 else
   if [ -z "$COMMAND" ] && shell_${LOCAL_MULTIPLEXER}_ls $DEST; then
@@ -62,7 +73,8 @@ else
   elif [ -z "$COMMAND" ] && [ "$DEST" == "root" ]; then
     # Local root shell
     window_title root
-    sudo $REMOTE_MULTIPLEXER
+    SUDO="sudo"
+    eval `shell_remote_multiplexer`
   elif [ -z "$COMMAND" ] && [ -f "$HOME/.screen/$DEST" ]; then
     # Local root shell
     window_title $DEST