]> git.huck.website - zshmux.git/commitdiff
zshmux creation
authorHuck Boles <huboles@protonmail.com>
Sat, 24 Sep 2022 20:57:10 +0000 (15:57 -0500)
committerHuck Boles <huboles@protonmail.com>
Sat, 24 Sep 2022 20:57:10 +0000 (15:57 -0500)
README.md
zshmux.zsh [new file with mode: 0644]

index 1a7652851436c0eea5c9b8798396ac86040aeb9c..817c18014be0aba5e7901aa1633fe788a38cb1ce 100644 (file)
--- a/README.md
+++ b/README.md
@@ -1,2 +1,10 @@
 # zshmux
-A super simple zsh plugin to attach to tmux sessions for new shells
+
+If a new shell is launched, *zshmux* quickly checks if there are any tmux sessions, or if the current shell is already in a tmux instance.
+If you are not already in a tmux session *zshmux* will ask if you want to attach a currently running session, or make a new session in the shell.
+
+## How to use:
+-Clone this repository
+    'git clone https://github.com/huboles/zshmux'
+-Source *zshmux* in your .zshrc
+    'source <path-to-zshmux>/zshmux/zshmux.zsh'
diff --git a/zshmux.zsh b/zshmux.zsh
new file mode 100644 (file)
index 0000000..137333d
--- /dev/null
@@ -0,0 +1,19 @@
+#!/bin/zsh
+
+if [[ -z $TMUX ]]; then
+    if tlist &> /dev/null ; then
+        printf 'Current tmux sessions:\n\n'
+        tlist
+    else
+        printf '\nNo tmux sessions active\n'
+    fi
+    printf '\n\tAttach session?: [name] (empty if none): '
+    read response
+    if [ -n "$response" ]; then
+        if tlist | grep -q "$response"; then
+            tmux attach-session -t $response 
+        else
+            tmux new-session -s $response
+        fi
+    fi
+fi