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: a tmux key that asks for a name and creates a new session

Tmux
~/tips/tip-tmux-prompt-new-session

bind S command-prompt -p 'new session:' 'new-session -A -s "%%"'

Creates and switches to a named session from inside tmux.

From inside tmux, starting a new session means detaching or typing a long command at the prompt. I prefer a key that asks for the name and does the rest.

bind S command-prompt -p 'new session:' 'new-session -A -s "%%"'

command-prompt shows the text after -p and waits for your answer. Whatever you type replaces %% in the template, and tmux runs the result. Started from inside tmux, new-session creates the session and switches your client to it, and -A attaches to it instead if a session with that name already exists.

The same pattern works for any command that needs input. Two prompts in one go look like this, with %1 and %2:

bind N command-prompt -p 'name:,folder:' 'new-window -n "%1" -c "%2"'

Press Escape at the prompt to cancel without running anything.

Watch out with quotes. If your answer contains a double quote, it breaks the template. tmux has %%% for that, which escapes quotes in the answer.

Further reading: tmux manual page (OpenBSD)

More Tmux tips tmux new -d -s report -x 200 -y 50 'top' tmux wait-for build-done set -g allow-passthrough on tmux kill-server Ctrl-b [ All Tmux tips (125) All topics

Link