summaryrefslogtreecommitdiff
path: root/scripts/tmux-sessionizer
diff options
context:
space:
mode:
authorJacob McDonnell <jacob@jacobmcdonnell.com>2024-12-05 13:49:22 -0500
committerJacob McDonnell <jacob@jacobmcdonnell.com>2024-12-05 13:49:22 -0500
commitf8d09c5cfd6d1d9595b64547dc9d29c63e40c5f2 (patch)
tree0dd9cfa47cfa0bd4d57d7789439cc86afbbdfa85 /scripts/tmux-sessionizer
parent29b1c791f6e319cdab828cee5f491ca1c38e41d1 (diff)
Moved .local/bin to scripts
Diffstat (limited to 'scripts/tmux-sessionizer')
-rwxr-xr-xscripts/tmux-sessionizer29
1 files changed, 29 insertions, 0 deletions
diff --git a/scripts/tmux-sessionizer b/scripts/tmux-sessionizer
new file mode 100755
index 0000000..3780e18
--- /dev/null
+++ b/scripts/tmux-sessionizer
@@ -0,0 +1,29 @@
+#!/bin/zsh
+
+# This script is stolen from The Primeagen
+# https://github.com/ThePrimeagen/.dotfiles/
+
+if [[ $# -eq 1 ]]; then
+ selected=$1
+else
+ selected=$(find ~/Documents/Projects ~ ~/.config ~/Documents/Projects/git ~/Documents/Projects/Experiments -mindepth 1 -maxdepth 1 -type d | fzf)
+fi
+
+if [[ -z $selected ]]; then
+ exit 0
+fi
+
+selected_name=$(basename "$selected" | tr . _)
+tmux_running=$(pgrep tmux)
+
+if [[ -z $TMUX ]] && [[ -z $tmux_running ]]; then
+ tmux new-session -s $selected_name -c $selected
+ exit 0
+fi
+
+if ! tmux has-session -t=$selected_name 2> /dev/null; then
+ tmux new-session -ds $selected_name -c $selected
+fi
+
+tmux switch-client -t $selected_name
+