Skip to content

Instantly share code, notes, and snippets.

@blueray453
Created June 15, 2023 07:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blueray453/5a0f46fdbfadb8a76aae63a07f0e66e5 to your computer and use it in GitHub Desktop.
Save blueray453/5a0f46fdbfadb8a76aae63a07f0e66e5 to your computer and use it in GitHub Desktop.
Auto start tmux session on fish shell
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