-
Notifications
You must be signed in to change notification settings - Fork 626
Tmux and Fish
Jonas Chevalier edited this page Mar 20, 2022
·
3 revisions
I use Tmux a lot in general development, and find it useful to separate my Tmux sessions on a per-project basis.
The following config saves me having to start Tmux when I switch to a project directory.
In ~/.config/direnv/direnvrc
:
session_name(){
export TMUX_SESSION_NAME="${*:?session_name needs a name as argument}"
}
In ~/.config/fish/config.fish
:
function autotmux --on-variable TMUX_SESSION_NAME
if test -n "$TMUX_SESSION_NAME" #only if set
if test -z $TMUX #not if in TMUX
if tmux has-session -t $TMUX_SESSION_NAME
exec tmux new-session -t "$TMUX_SESSION_NAME"
else
exec tmux new-session -s "$TMUX_SESSION_NAME"
end
end
end
end
Used like this (in <project>/.envrc
):
session_name Project
From then on, z project
(because of the excellent fasd
) jumps me to that project directory, and starts up a Tmux session called "Project." If there's already such a session, it merely attaches to that session (noticeable because the client name will be a number), which is my prompt to ^D
and find the terminal I'm using for that project - easy, because the terminal title will be the same as the Tmux session name.
See also: Tmux