Is it possible to use an environment variable in a tmux.conf file? I am trying to set a default-path to an environment variable. Currently what I am trying is:

set -g default-path $MYVAR

further I would like to check if $MYVAR is set already so I could do:

if($MYVAR == "") set-environment -g MYVAR /somepath/

Any ideas?


Yes it looks like it is possible to expand shell variables in .tmux.conf file It looks like it's not required, but a good idea to quote them, esp. I was able to do this successfully with the status bar options just now.

# In ~/.tmux.conf:
set -g status_left "$MYVAR etc: "

$ export MYVAR="Shell stuff"
$ tmux

I don't know about any 'if' or other control structures in the config, but there might be.

| improve this answer | |
  • I cant get this to work in a tmux script file. I am sure $MYVAR is set, and I run the script and it fails. set -g default-path "$MYVAR" split-window -h it splits the window but default-path is not set to $MYVAR – Digital Powers Jun 22 '11 at 20:57
  • 3
    ok i found where things are breaking down, if I set the environment variable before i run tmux then i can use it in my tmux.conf file. If i set the environment variable, either in tmux.conf using set-environment or after i am in tmux then reload the tmux.conf it doenst use my new variables I have set. Any idea why? – Digital Powers Jun 22 '11 at 21:25
  • The shells you run inside tmux are child processes of tmux. Changing things inside those environments is not going to propogate back up the line to the tmux parent process. It only works the other way because tmux becomes a child of the shell you launched it from. I assume the config reload is similar in that it's launching a new child of the parent process. – Caleb Jun 22 '11 at 21:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.