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 respawn-pane -k restarts the command in a pane without closing it

Tmux
~/tips/tip-tmux-respawn-pane-k

tmux respawn-pane -k

Restarts a pane's program in place, with the same layout and starting command.

When a dev server or a log tail in a tmux pane gets stuck, I don’t want to close the pane, lose the layout and type the command again. tmux can restart it in place.

tmux respawn-pane -k

-k kills the command that is running in the pane. Without a new command, tmux runs the command the pane was created with (or last respawned with) again. Same pane, same size, same spot in the layout.

You can give it another command or directory too:

tmux respawn-pane -k -c ~/projects/site 'npm run dev'

-c sets a new working directory for the pane and -e adds an environment variable, like it does for new-window.

Without -k, the man page says the pane must already be inactive, so it is for panes whose program has exited. That pairs well with the remain-on-exit option: the pane stays visible after the program stops, you read the last error, and then respawn it.

A binding for it in ~/.tmux.conf:

bind-key R respawn-pane -k

Caveat: -k really kills whatever is running there, unsaved state and all. Respawning a pane with an editor or a half-finished database migration in it is a bad idea, so check which pane is active before you press the key.

Further reading: tmux manual: respawn-pane, On this site: tmux pipe-pane -o writes a pane's output to a file

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