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 show-environment -s prints the session environment as shell commands

Tmux
~/tips/tip-tmux-show-environment-s

tmux show-environment -s SSH_AUTH_SOCK

Prints a tmux session variable as a shell command, so an old pane can pick up the new value.

A long-lived tmux session keeps its own copy of some environment variables. After I reconnect over SSH, a shell in an old window can still point to an agent socket that no longer exists.

tmux keeps an environment per session. show-environment prints it, and with -s the output is formatted as Bourne shell commands, ready to run in the current shell.

tmux show-environment -s SSH_AUTH_SOCK

That prints an assignment line for a Bourne-style shell. To apply it in one go:

eval "$(tmux show-environment -s SSH_AUTH_SOCK)"

Without a variable name the command prints everything, and -g shows the global environment instead of the session one. Variables that were removed from the environment are printed with a - in front. set-environment is the matching setter, and set-environment -u unsets a variable.

The session option update-environment decides which variables tmux copies from the client into the session environment when a session is created or reattached. Check its value with:

tmux show -g update-environment

The value you get is the one tmux has stored, which is not always what your outer shell has now. Since eval runs whatever text it gets, read the output once before you evaluate it.

Further reading: tmux manual

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