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-message -p prints facts like the session name

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

tmux display-message -p '#S' # session name

Prints a tmux format such as the session name or pane path to the terminal, for use in scripts.

Scripts often need to know where they run. tmux can tell them, using the same formats as the status bar.

tmux display-message -p '#S'                  # session name
tmux display-message -p '#{pane_current_path}'  # folder of the pane

Without -p the text is shown in the status bar for a moment. With -p it goes to standard output, so you can store it in a variable: name=$(tmux display-message -p '#S').

The formats are the same #{...} variables the status line uses. tmux display-message -a lists every variable and its current value, which is a quick way to find the one you need.

Outside tmux the command fails, because there is no current session. Check for the TMUX environment variable in your script before you rely on it.

Try it without risk: start a throwaway session with tmux new -s scratch, use the shortcut or command above there, look at what changes, and close it again with tmux kill-session -t scratch. Nothing else on your machine is touched.

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

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