NixOS_NoFlake/home/config/fish/functions/ts.fish

67 lines
2.6 KiB
Fish

function ts --description "Tmux session manager with fuzzy search and quick jump"
echo -e ""
# 1. Show Active Sessions
set -l active_sessions (tmux list-sessions 2>/dev/null)
if test -n "$active_sessions"
echo -e (set_color 99ff99)"󱫟 Active Sessions:"(set_color normal)
for line in $active_sessions
echo -e " $line"
end
echo ""
else
echo -e (set_color 555555)"(No active sessions)"(set_color normal)
echo ""
end
# 2. Provide choices
echo -e (set_color 00afaf)"󰒓 Select an option:"(set_color normal)
echo -e " [1] Pick from active sessions (Fuzzy search)"
echo -e " [2] Create NEW custom session"
echo -e " [w] Enter Tmuxinator Workspaces"
echo -e " [d] Detach from current session"
echo -e " [x] Kill a session"
echo -e " [Enter] Quick jump to "(set_color -o)"Main"(set_color normal)
echo ""
read -l -P "Choice > " choice
switch "$choice"
case 1
set -l session (tmux list-sessions -F "#{session_name}" 2>/dev/null | fzf --exit-0 --height=15% --reverse --header="Select Session")
if test -n "$session"
if set -q TMUX
tmux switch-client -t "$session"
else
tmux attach-session -t "$session"
end
end
case 2
read -l -P "Enter name for new session: " new_name
if test -n "$new_name"
env -u TMUX tmux new-session -d -s "$new_name" 2>/dev/null
if set -q TMUX
tmux switch-client -t "$new_name"
else
tmux attach-session -t "$new_name"
end
end
case d D
if set -q TMUX; tmux detach-client; else; echo "You aren't in a tmux session!"; end
case w W
if type -q tmuxinator
tmuxinator start Workspace
else
echo (set_color red)"Error: tmuxinator is not installed."(set_color normal)
end
case x X
set -l session (tmux list-sessions -F "#{session_name}" 2>/dev/null | fzf --exit-0 --height=15% --reverse --header="Select Session to KILL")
if test -n "$session"
tmux kill-session -t "$session"
echo "Killed session: $session"
ts
end
case "" "*"
env -u TMUX tmux new-session -d -s Main 2>/dev/null
if set -q TMUX; tmux switch-client -t Main; else; tmux attach-session -t Main; end
end
commandline -f repaint
end