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: set -s history-file keeps your tmux command prompt history after a restart

Tmux
~/tips/tip-tmux-history-file

set -s history-file ~/.tmux_history

Saves the commands you type after Ctrl-b : to a file, so they come back later.

The tmux command prompt has a history: press Ctrl-b :, then the Up arrow, and the last command is back. That history lives in the server, so it is gone after a reboot or a tmux kill-server. One option fixes that.

set -s history-file ~/.tmux_history

It is a server option, hence the -s. When the option is not empty, tmux writes the prompt history to that file when the server exits and loads it again when a new server starts. The ~ is expanded to your home folder. Put the line in ~/.tmux.conf, so every new server knows where to find the history.

The file is plain text, one command per line with a small type in front, like command:select-layout tiled. How many lines tmux keeps is set by prompt-history-limit, 100 by default:

tmux show -s prompt-history-limit

This is one of those options I’d turn on and forget. Long commands like a resize with exact numbers or a join-pane -s with a target are exactly the ones you don’t want to type again after an update.

Two caveats. tmux writes the file when the server exits, so a server that is killed hard or loses power takes the history of that run with it. And anything you type at the prompt ends up in the file, including a send-keys line with a password or token in it. I’d keep secrets out of the tmux prompt anyway, but with this option on it matters more.

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 tmux list-keys -T prefix ] set -g prefix2 C-a bind S run-shell -b '~/bin/sync-notes.sh' set -g status-justify centre All Tmux tips (133) All topics

Link