Created
June 15, 2023 07:24
-
-
Save blueray453/5a0f46fdbfadb8a76aae63a07f0e66e5 to your computer and use it in GitHub Desktop.
Auto start tmux session on fish shell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if status is-interactive | |
if not set -q TMUX | |
if tmux list-sessions &>/dev/null | |
set -l array | |
for i in (tmux list-sessions -F "#{session_name} #{session_attached}") | |
set -a array $i | |
end | |
if set -q array | |
for j in (seq 1 100) | |
if echo $array | grep -w -q "default$j" | |
if test (echo $array[$j] | cut -d' ' -f2) -eq 0 | |
# kill unattached sessions | |
tmux kill-session -t $(echo $array[$j] | cut -d' ' -f1) | |
end | |
else | |
# create session if no session with this name exist | |
tmux new-session -s default$j -c $PWD | |
break | |
end | |
end | |
else | |
# create default0 session if no session exist | |
tmux new-session -s default0 -c $PWD | |
end | |
else | |
# create default0 session if no session exist | |
tmux new-session -s default0 -c $PWD | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment