Zellij has some genuinely nice features. It’s much more discoverable and less foreboding than vanilla tmux. It just did this thing with Blink that ended up slowly chewing into the number of available lines on the screen I could never sort out, so back to tmux.
I’ve never been comfortable with tmux’s default leader, so my first change was to make C-space the leader:
set -g prefix C-space
… and to help me remember the few things I care about, I modified the status bar to add some help:
set -g status-right "c:new ←/→:nav ,:rename d:detach %H:%M"
… but I don’t like the leader key generally, so I made some keybindings with meta. Most of them stick to the base tmux key, iirc, but just let me chord them with meta vs. using the leader key:
# Some basics
unbind C-b
bind -n M-c new-window -c "#{pane_current_path}"
bind -n M-r source-file ~/.tmux.conf
bind -n M-d detach
bind -n M-, command-prompt -I "#W" "rename-window '%%'"
bind -n M-x command-prompt
bind -n M-z resize-pane -Z
# Option+Shift+arrows
bind -n S-M-Left previous-window
bind -n S-M-Right next-window
# split panes using | and - (I borrowed this idea from someone -- the defaults are incomprehensible to me)
bind -n M-| split-window -h
bind -n M-- split-window -v
unbind '"'
unbind %All those pretty much let me use tmux in the “one session for everything” pattern. Log in, fire it up, rejoin where you left off.
To help support my most common use case, which is logging into my Mac mini from my laptop or iPad, I added some conditional logic to my .zshrc template in chezmoi
{{- if eq .chezmoi.hostname "mikes-mac-mini" }}
# Auto-reconnect to tmux on SSH/mosh sessions
if [[ -z "$TMUX" ]] && { [[ -n "$SSH_CONNECTION" ]] || [[ -n "$SSH_TTY" ]] || [[ "$(ps -o comm= -p $PPID 2>/dev/null)" == "mosh-server" ]]; }; then
tmux new-session -A -s coding
fi
{{- end }}…so if I’m signing in from an SSH session, I get dropped back into my standard tmux coding session.
Graduating to multi-session tmux
Beyond the ergonomics of tmux commands and the convenience of being able to get back into my old session, I was struggling a little with doing a bunch of things inside the same session. Windows weren’t very helpfully labeled, so I was constantly renaming them, tabbing around between them was getting tedious, so I decided to adopt a multi-session approach, opening a new tmux in each of my working directories.
That was made super easy by sesh. You just run sesh picker to get an interactive list of your tmux sessions and (if you have zoxide installed) your most frequently visited directories. So, pick a session to rejoin it, or pick a directory to open up a tmux session inside it.
To make hopping around between sessions simpler, I added a M-s keystroke:
bind -n M-s choose-tree -Zs
That gives me a list of my open tmux sessions I can cursor around in and/or pick a window from, with a quick preview of the windows in a given session when I cursor over it.
To support a multi-session approach for ssh logins, I modified my .zshrc:
# Auto-reconnect to tmux on SSH/mosh sessions
if [[ -n "$SSH_CONNECTION" ]] && [[ -z "$TMUX" ]] && [[ $- == *i* ]]; then
session=$(sesh list -i | fzf --ansi --height 40% --reverse --prompt 'sesh > ')
[[ -n "$session" ]] && exec sesh connect "$session"
fiSo when I ssh into the mini now, I get that interactive sesh list and I can rejoin the right project session, or go to some directory and get a new tmux session inside it (or bail with esc and go somewhere else).
Side note: zoxide is so nice. Instead of cd + some long path you just z some-fragment-of-a-dir-you've-visited and go there. It remembers where you’ve been.
The final piece was landing on a color treatment for all of it:
set -g window-style 'bg=colour236'
set -g window-active-style 'bg=colour234'
set -g window-status-current-style "fg=colour231,bg=colour39,bold"
set -g status-style "fg=colour231,bg=colour25"
set -g status-left "#[fg=white,bg=colour22,bold] #S #[default] "That gives me a WordPerfect 5.1 blue status bar with the active window getting a lighter blue background and white/bold text, and the current session name getting a green background with white/bold text. Much easier to know where I am both by session and window.
Putting it all together, tmux feels much more fluid.
