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 split-window -e starts a pane with its own environment variable

Tmux
~/tips/tip-tmux-split-env

tmux split-window -e AWS_PROFILE=staging

Gives one new pane an extra environment variable without touching others.

Exporting a variable in a shell only affects that shell. When I want a new pane to start with a variable set, tmux can pass it along.

tmux split-window -e AWS_PROFILE=staging

The new pane starts with AWS_PROFILE set to staging, on top of the normal session environment. Other panes and the session itself are not changed. You can repeat -e for several variables.

It is the same flag on new-window and new-session, so a window for a different project could look like this:

tmux new-window -n api -e APP_ENV=test -c ~/projects/api

That combination of a name, a folder and an environment is how I’d set up panes in a startup script, because the shell in that pane needs no extra typing.

Check it from inside the new pane with echo $AWS_PROFILE. Keep in mind that the value belongs to that pane only. A split you open from it later with Ctrl-b % starts from the session environment again, so it won’t have the variable unless you give -e again.

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