As I use the terminal for more tasks, I often find myself with several tmux sessions active at once.

Several tmux sessions.

To make managing these sessions easier, I added a few lines to my tmux.conf.

Before adding any new keybindings, a tmux command I use a lot was prefix s, which shows a list of all of your sessions with a preview and allows you to switch between them with hjkl. This is sweet because the alternative would be detaching and reattaching tmux every time you needed to switch sessions. However, I didn’t have a convenient way to create new sessions without detaching tmux. Thus, I added the following mapping:

bind S new-session

I had a similar issue with killing sessions. Whenever I was done with a session, I would exit the session by hitting prefix x until all of the panes in the session were killed. This would close session and simultaneously exit tmux. There are two issues here: (1) I don’t want to exit tmux, and (2) I don’t want to need to spam prefix x a bunch. Thus, I added two lines:

set-option -g detach-on-destroy off   # Solves (1)
bind K confirm kill-session           # Solves (2)

Finally, I wanted a convenient to set the home directory of a tmux session. The home directory is the directory that new panes and windows default to opening in. Thus, I added a mapping to set the home directory to the current working directory:

bind C attach-session -c "#{pane_current_path}"

These changes solved some nagging inconveniences that I have been experiencing in tmux for a long time. Now, using tmux is a lot more fun. For your copy-pasting pleasure, here are all of the lines in a single code block:

set-option -g detach-on-destroy off

bind S new-session
bind K confirm kill-session
bind C attach-session -c "#{pane_current_path}"

Sources