]> gitweb.fluxo.info Git - termplex.git/commitdiff
Feat: support for starting detached tmux sessions
authorSilvio Rhatto <rhatto@riseup.net>
Fri, 2 Aug 2024 18:27:29 +0000 (15:27 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Fri, 2 Aug 2024 18:27:29 +0000 (15:27 -0300)
shell
wtmux

diff --git a/shell b/shell
index 0dd64e66abc00ed49e617602123026ee7b517972..df569e91ecdf1ad90c0bb750f101ace5c245be85 100755 (executable)
--- a/shell
+++ b/shell
@@ -59,6 +59,9 @@ fi
 # Set default screen title
 window_title $DEST
 
+# Shift args
+shift 2
+
 # Dispatcher
 if [ "$BASENAME" == "shells" ]; then
   # Remote screen shell using $AUTOSSH
@@ -66,7 +69,7 @@ if [ "$BASENAME" == "shells" ]; then
     SUDO="sudo"
     $AUTOSSH $DEST -t -- "`shell_remote_multiplexer`"
   else
-    $AUTOSSH $DEST -t -- "`shell_remote_multiplexer` $COMMAND"
+    $AUTOSSH $DEST -t -- "`shell_remote_multiplexer` $COMMAND $*"
   fi
 else
   if [ -z "$COMMAND" ] && shell_${LOCAL_MULTIPLEXER}_ls $DEST; then
@@ -80,14 +83,14 @@ else
   elif [ -z "$COMMAND" ] && ( [ -f "$HOME/.screen/$DEST" ] || [ -f "$HOME/.tmux/$DEST" ] ); then
     # Local root shell
     window_title $DEST
-    shell local $DEST
+    shell local $DEST $*
   elif [ "$DEST" == "local" ]; then
     # Local screen shell
     window_title $COMMAND
-    $LOCAL_MULTIPLEXER $COMMAND
+    $LOCAL_MULTIPLEXER $COMMAND $*
   else
     # Remote shell using $AUTOSSH
-    $AUTOSSH $DEST -t -- $COMMAND
+    $AUTOSSH $DEST -t -- $COMMAND $*
   fi
 fi
 
diff --git a/wtmux b/wtmux
index bef84c6d9ea7889467417501ad5432bad68ff8cf..aa48386dd3da8faa17a5908e9a5de1acc46ff692 100755 (executable)
--- a/wtmux
+++ b/wtmux
@@ -1,3 +1,4 @@
+#!/usr/bin/env bash
 #
 # Worktemux: tmux session wrapper
 # https://robots.thoughtbot.com/a-tmux-crash-course
 
 # Default options.
 opts=""
+name="$1"
+state="$2"
 
 # Session selection.
-if [ ! -z "$1" ]; then
-  if ! tmux list-sessions 2> /dev/null | grep -q "^$1:"; then
-    session="new-session -d -s $1"
+if [ ! -z "${name}" ]; then
+  if ! tmux list-sessions 2> /dev/null | grep -q "^${name}:"; then
+    session="new-session -d -s ${name}"
 
-    if [ "$1" = "root" ]; then
+    # Use a unique, per-session name
+    #session"${session} -t ${name}"
+
+    if [ "${name}" = "root" ]; then
       sudo tmux attach
       exit
-    elif [ -f "$HOME/.tmux/$1" ]; then
-      opts="$HOME/.tmux/$1"
+    elif [ -f "$HOME/.tmux/${name}" ]; then
+      opts="$HOME/.tmux/${name}"
     elif [ -f "$HOME/.tmux/base" ]; then
       opts="$HOME/.tmux/base"
     else
@@ -37,7 +43,9 @@ if [ ! -z "$1" ]; then
     fi
   fi
 
-  tmux attach -t $1
+  if [ -z "$state" ] || [ "$state" == "attached" ]; then
+    tmux attach -t ${name}
+  fi
 else
   tmux
 fi