Sal's

Cool tmux trick: scratch popup

One thing I love about the i3 window manager is what’s called the scratchpad. The scratchpad lets me toggle the visibility of a floating window with a hotkey. It’s great for keeping notes or a terminal at the ready, available in any workspace.

It turns out that it’s easy to add a similar feature to tmux. Here’s my relevant config:

bind-key Space if-shell -F '#{==:#{session_name},scratch}' {
    detach-client
} {
    display-popup -d '#{pane_current_path}' -w 90% -h 90% -E "tmux new-session -A -s scratch"
}

With this config, <prefix> + Space will toggle a floating popup with the “scratch” session. The logic, in short: if I’m already in the scratch session, hide it with detach-client. Otherwise, display a popup with that session.

If I don’t want the popup to have its own persistent session, it can be even simpler:

bind-key t display-popup -E -w 90% -h 90% -d '#{pane_current_path}'

That will show a popup of a new terminal in the current path. I can’t use it for long-running things where I need to toggle it on and off, but it’s good for one-off commands.

I’ve been using both of these quite a lot. If you can spot any room for improvement or have your own tmux tips to share, please email me!

#Tmux