Creating a "kill current session" shortcut in Tmux

Is it possible to create a shortcut in Tmux which would kill current session? Typing "kill-session -t mysession" is not very convenient

I imagine something like

bind X kill-session -t $currentsesion

what I do not understand how to let bind know which session is current.


After playing around I found that I can make following shorcut which behaves the way I want:

  • Kills current session
  • Leaves all other sessions intact

bind X confirm-before "kill-session -t ''"

This solution seems to work but also looks like a hack. I hope there is a better way to do this.

EDIT

As pointed out in the comments, omitting the -t parameter will cause tmux to automatically use the current session so the code could also be shortened to:

bind X confirm-before kill-session


You can define shortcuts for tmux by editing ~/.tmux.conf, and supplying a suitable bind-key line. The manual page shows some examples.

For additional reading:

  • Overriding tmux shortcuts
  • A tmux Primer
  • screen to tmux: A Humble Quick-start Guide