COMMAND="$2"
#LOCAL_MULTIPLEXER="wscreen"
LOCAL_MULTIPLEXER="wtmux"
-REMOTE_MULTIPLEXER="screen -x"
MONITORING="-M $(($RANDOM + 1024))"
AUTOSSH="autossh $MONITORING"
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
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
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