From 1d3a4b8cf936e0fc48c96bd3ae415b4a84fb17a2 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Fri, 25 Aug 2017 08:24:02 -0300 Subject: Support tmux and screen as fallback on root and remotes --- shell | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/shell b/shell index 31d2823..90e3278 100755 --- 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 -- cgit v1.2.3