From 771d23fe76122647b75736e5f4fa2cf22b1cf7ba Mon Sep 17 00:00:00 2001 From: CronyAkatsuki Date: Fri, 10 Nov 2023 21:41:43 +0100 Subject: [PATCH] Tmux smart --- t | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100755 t diff --git a/t b/t new file mode 100755 index 0000000..3f28719 --- /dev/null +++ b/t @@ -0,0 +1,26 @@ +#!/bin/sh + +[ "$1" ] && result=$(zoxide query $1) || result=$(zoxide query -l | fzf --prompt "Choose directory: ") + +[ -z "$result" ] && exit 0 + +name=$(basename $result) + +session=$(tmux list-sessions | grep $name | awk '{print $1}' | sed 's/.$//') + +if [ -z "$TMUX" ]; then + if [ -z "$session" ]; then + cd $result + tmux new-session -s $name + else + tmux attach -t $session + fi +else + if [ -z "$session" ]; then + cd $result + tmux new-session -d -s $name + tmux switch-client -t $name + else + tmux switch-client -t $session + fi +fi