brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: tmux display-menu builds a small menu of your own commands

Tmux
~/tips/tip-tmux-display-menu

bind m display-menu -T Tools \

Opens a menu on a tmux key with your own commands, each with a shortcut letter.

Some tmux commands I want now and then, but not often enough to remember a key for them. display-menu puts them in a little menu with a title, and one key opens it.

bind m display-menu -T Tools \
  'Top' t 'new-window top' \
  '' \
  'Reload config' r 'source-file ~/.tmux.conf' \
  'Close other panes' k 'kill-pane -a'

Every item is three arguments: the name, a shortcut key and the tmux command. An empty name makes a separator line, without key or command. A name that starts with a hyphen is shown dim and can’t be chosen, which works as a small heading. -T sets the title.

Put the block in ~/.tmux.conf and reload. Ctrl-b m opens the menu. Press the shortcut to run an item, or use Up, Down and Enter. q closes the menu without doing anything.

With -x C -y C the menu opens in the middle of the terminal, and -x R puts it on the right side. The names are formats, so something like 'Zoom #{pane_index}' shows the current pane number.

I’d use this for the commands that are easy to get wrong, like closing every other pane. Seeing the name in a menu before you press the key is a nice extra check.

A menu needs a client to draw on. Run tmux display-menu ... from a plain shell outside tmux and you get no current client, so bind it to a key or run it from the Ctrl-b : prompt. And if the menu is taller than your terminal, tmux does not show it at all. Keep it short.

Further reading: tmux manual page (OpenBSD), tmux wiki: Getting Started

Going deeper: Guide: advanced tmux, a config that grows with you, formats, layouts and more

More Tmux tips set -s extended-keys on set -s history-file ~/.tmux_history tmux list-keys -T prefix ] set -g prefix2 C-a bind S run-shell -b '~/bin/sync-notes.sh' All Tmux tips (133) All topics

Link