dotfiles/fish/config.fish
Irrlicht ae62063e4c [fish] Auto start Tmux on launch
Very basic function to check wether the current Fish instance is in a
TMUX session. If not, start a new tmux session. Possible to attach to an
existing one on start.

Behavior could be made more elaborate and count if at least one Fish
instance is within a Tmux session. Attach to a potential Tmux session
existing. This would allow for having a Tmux session always running on
the system.
2025-06-17 01:07:14 +02:00

29 lines
872 B
Fish

# Function to auto-launch tmux session on start
# If option a/attach is given, will attach to an existing session.
# Does nothing if a session is already running, regardless of whether
# current Fish instance is within a Tmux session or not
function auto_launch_tmux
argparse "a/attach" -- $argv
# Check if already in a tmux session
if ! string match -r tmux $TERM
set tmux_session $(tmux ls| wc -l)
# Test if there's at least one Tmux session running
if test $tmux_session -eq 0
tmux new
else
if set -ql _flag_attach
echo Attach
tmux attach-session -t 0
end
end
end # else already in Tmux, nothing to do
end
if status is-interactive
abbr --add txl tmux ls
abbr --add txa tmux a
abbr --add txn tmux new
auto_launch_tmux
end