aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2017-08-25 08:24:02 -0300
committerSilvio Rhatto <rhatto@riseup.net>2017-08-25 08:24:02 -0300
commit1d3a4b8cf936e0fc48c96bd3ae415b4a84fb17a2 (patch)
treea54a78c9a9983ebe9bba87985c4552148472dee6
parent9251d79ccfafcec99beea6ef1d253d299d1980df (diff)
downloadtermplex-1d3a4b8cf936e0fc48c96bd3ae415b4a84fb17a2.tar.gz
termplex-1d3a4b8cf936e0fc48c96bd3ae415b4a84fb17a2.tar.bz2
Support tmux and screen as fallback on root and remotes
-rwxr-xr-xshell20
1 files 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