]> gitweb.fluxo.info Git - termplex.git/commitdiff
Full session support at wtmux
authorSilvio Rhatto <rhatto@riseup.net>
Mon, 21 Aug 2017 02:17:30 +0000 (23:17 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Mon, 21 Aug 2017 02:17:30 +0000 (23:17 -0300)
wtmux

diff --git a/wtmux b/wtmux
index 5a3f2a865569f28d86a5a67620d846e217bfc706..4c6d336548b6de251b54210ef2e02e43041f7c85 100755 (executable)
--- a/wtmux
+++ b/wtmux
@@ -2,30 +2,38 @@
 # Worktemux: tmux session wrapper
 # https://robots.thoughtbot.com/a-tmux-crash-course
 #
+# Alternatives:
+# https://github.com/tmuxinator/tmuxinator
+# https://github.com/tony/tmuxp
 
 # 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 ! tmux list-sessions 2> /dev/null | grep -q "^$1:"; then
+    session="new-session -d -s $1"
+
+    if [ "$1" = "root" ]; then
+      sudo tmux attach
+      exit
+    elif [ -f "$HOME/.tmux/$1" ]; then
+      opts="$HOME/.tmux/$1"
+    elif [ -f "$HOME/.tmux/base" ]; then
+      opts="$HOME/.tmux/base"
+    else
+      opts=""
+    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=""
+    # Start session.
+    if [ ! -z "$opts" ]; then
+      tmux $session \; source-file $opts
+    else
+      tmux $session
+    fi
   fi
-fi
 
-# Start session.
-tmux $opts $session
+  tmux attach -t $1
+else
+  tmux
+fi