{
"path": "/posts/2026-05-09-figuring-out-tmux/",
"site": "https://mike.puddingtime.org",
"tags": [
"tmux",
"tools",
"shell",
"configs"
],
"$type": "site.standard.document",
"title": "Figuring out tmux",
"description": "[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 wi...",
"publishedAt": "2026-05-09T18:13:35.364Z",
"textContent": "[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. \n\nI've never been comfortable with tmux's default leader, so my first change was to make `C-space` the leader: \n\n`set -g prefix C-space`\n\n... and to help me remember the few things I care about, I modified the status bar to add some help:\n\n`set -g status-right \"c:new ←/→:nav ,:rename d:detach %H:%M\"`\n\n... 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: \n\n\n```\n# Some basics\nunbind C-b\nbind -n M-c new-window -c \"#{pane_current_path}\"\nbind -n M-r source-file ~/.tmux.conf\nbind -n M-d detach\nbind -n M-, command-prompt -I \"#W\" \"rename-window '%%'\"\nbind -n M-x command-prompt\nbind -n M-z resize-pane -Z\n\n# Option+Shift+arrows\nbind -n S-M-Left previous-window\nbind -n S-M-Right next-window\n\n# split panes using | and - (I borrowed this idea from someone -- the defaults are incomprehensible to me)\n\nbind -n M-| split-window -h\nbind -n M-- split-window -v\nunbind '\"'\nunbind %\n\n```\n\nAll those pretty much let me use tmux in the \"one session for everything\" pattern. Log in, fire it up, rejoin where you left off. \n\nTo 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][]\n\n```\n{{- if eq .chezmoi.hostname \"mikes-mac-mini\" }}\n# Auto-reconnect to tmux on SSH/mosh sessions\nif [[ -z \"$TMUX\" ]] && { [[ -n \"$SSH_CONNECTION\" ]] || [[ -n \"$SSH_TTY\" ]] || [[ \"$(ps -o comm= -p $PPID 2>/dev/null)\" == \"mosh-server\" ]]; }; then\n tmux new-session -A -s coding\nfi\n{{- end }}\n```\n\n...so if I'm signing in from an SSH session, I get dropped back into my standard tmux coding session. \n\n## Graduating to multi-session tmux\n\nBeyond 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. \n\nThat 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. \n\nTo make hopping around between sessions simpler, I added a `M-s` keystroke:\n\n`bind -n M-s choose-tree -Zs`\n\nThat 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. \n\nTo support a multi-session approach for ssh logins, I modified my `.zshrc`: \n\n```\n# Auto-reconnect to tmux on SSH/mosh sessions\nif [[ -n \"$SSH_CONNECTION\" ]] && [[ -z \"$TMUX\" ]] && [[ $- == *i* ]]; then\n session=$(sesh list -i | fzf --ansi --height 40% --reverse --prompt 'sesh > ')\n [[ -n \"$session\" ]] && exec sesh connect \"$session\"\nfi\n```\n\nSo 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). \n\nSide 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. \n\nThe final piece was landing on a color treatment for all of it: \n\n```\nset -g window-style 'bg=colour236'\nset -g window-active-style 'bg=colour234'\nset -g window-status-current-style \"fg=colour231,bg=colour39,bold\"\nset -g status-style \"fg=colour231,bg=colour25\"\nset -g status-left \"#[fg=white,bg=colour22,bold] #S #[default] \"\n```\n\nThat 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. \n\nPutting it all together, tmux feels much more fluid.\n\n\n[zoxide]: https://github.com/ajeetdsouza/zoxide\n[sesh]: https://github.com/joshmedeski/sesh\n[chezmoi]: https://www.chezmoi.io\n[Zellij]: https://zellij.dev"
}