]> gitweb.fluxo.info Git - termplex.git/commitdiff
Adds wtmux
authorSilvio Rhatto <rhatto@riseup.net>
Thu, 19 May 2016 21:53:35 +0000 (18:53 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Thu, 19 May 2016 21:53:35 +0000 (18:53 -0300)
shell
wtmux [new file with mode: 0755]

diff --git a/shell b/shell
index 0588fbe48fe1bf98d6d74424347ef9b13800894f..36aa30d49200d16f13883cfb445017b785a98292 100755 (executable)
--- a/shell
+++ b/shell
@@ -7,6 +7,7 @@
 BASENAME="`basename $0`"
 DEST="$1"
 COMMAND="$2"
+MULTIPLEXER="wscreen"
 
 # Set window title
 # http://stackoverflow.com/questions/899609/gnu-screen-run-script-that-sends-commands-to-the-screen-session-it-is-being-run
@@ -39,7 +40,7 @@ if [ "$BASENAME" == "shells" ]; then
 else
   if [ -z "$COMMAND" ] && screen -ls $DEST | grep -q "There is a screen on"; then
     # Local existing screen shell
-    wscreen $DEST
+    $MULTIPLEXER $DEST
   elif [ -z "$COMMAND" ] && [ "$DEST" == "root" ]; then
     # Local root shell
     window_title root
@@ -51,7 +52,7 @@ else
   elif [ "$DEST" == "local" ]; then
     # Local screen shell
     window_title $COMMAND
-    wscreen $COMMAND
+    $MULTIPLEXER $COMMAND
   else
     # Remote shell using autossh
     autossh $DEST -t -- $COMMAND
diff --git a/wtmux b/wtmux
new file mode 100755 (executable)
index 0000000..5a3f2a8
--- /dev/null
+++ b/wtmux
@@ -0,0 +1,31 @@
+#
+# Worktemux: tmux session wrapper
+# https://robots.thoughtbot.com/a-tmux-crash-course
+#
+
+# Default options.
+opts=""
+
+# Session selection.
+if [ ! -z "$1" ]; then
+  if tmux list-sessions 2> /dev/null | grep -q "^$1:"; then
+    tmux attach -t $1
+    exit $?
+  else
+    session="new -s $1"
+  fi
+
+  if [ "$1" == "root" ]; then
+    sudo tmux attach
+    exit
+  elif [ -f "$HOME/.tmux/$1" ]; then
+    opts="-f $HOME/.tmux/$1"
+  elif [ -f "$HOME/.tmux/base" ]; then
+    opts="-f $HOME/.tmux/base"
+  else
+    opts=""
+  fi
+fi
+
+# Start session.
+tmux $opts $session