diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2014-09-18 16:36:52 -0300 |
---|---|---|
committer | Silvio Rhatto <user@example.org> | 2014-09-18 16:36:52 -0300 |
commit | 6acb9754f95be9713f09bbac00dc08d31c465a21 (patch) | |
tree | 70b1448cbe5f193e49d6754cf89e9bf5c46e48be /shell | |
download | termplex-6acb9754f95be9713f09bbac00dc08d31c465a21.tar.gz termplex-6acb9754f95be9713f09bbac00dc08d31c465a21.tar.bz2 |
Initial import
Diffstat (limited to 'shell')
-rwxr-xr-x | shell | 54 |
1 files changed, 54 insertions, 0 deletions
@@ -0,0 +1,54 @@ +#!/bin/bash +# +# Simple autossh and screen wrapper. +# + +# Parameters +BASENAME="`basename $0`" +DEST="$1" +COMMAND="$2" + +# Set screen title +# http://stackoverflow.com/questions/899609/gnu-screen-run-script-that-sends-commands-to-the-screen-session-it-is-being-run +function screen_title { + if [ -n "$STY" ]; then + screen -X title $1 + fi +} + +# Syntax check +if [ -z "$DEST" ]; then + exit 1 +fi + +# Set default screen title +screen_title $DEST + +# Dispatcher +if [ "$BASENAME" == "shells" ]; then + # Remote screen shell using autossh + if [ "$COMMAND" == "root" ]; then + autossh $DEST -t -- sudo screen -x + else + autossh $DEST -t -- screen -x $COMMAND + fi +else + if [ -z "$COMMAND" ] && screen -ls $DEST | grep -q "There is a screen on"; then + # Local existing screen shell + wscreen $DEST + elif [ -z "$COMMAND" ] && [ "$DEST" == "root" ]; then + # Local root shell + screen_title root + sudo screen -x + elif [ "$DEST" == "local" ]; then + # Local screen shell + screen_title $COMMAND + wscreen $COMMAND + else + # Remote shell using autossh + autossh $DEST -t -- $COMMAND + fi +fi + +# Restore screen title +screen_title terminal |