Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I start tmux with my current environment? [closed]

Tags:

tmux

Or at least the part of it, that makes sense.

More specifically I have some environment variables, that have been exported by running a script, to create an adequate environment for the task at hand. When I run tmux these variables are nowhere to be seen, neither in the global or the session environment. Of course I can run this script again but ...

I'd be satisfied if I could specify the particular vars in my .tmux.conf file however:

set-environment VAR $VAR 

Does not do what I'd expect.

Thanks in advance :)

Ah, I think I know why.

When starting a second session of tmux, say in another terminal, it copies the environment from the first one. The first one pretty much takes the current environment of the calling shell and adds some tmuxiness to it.

My current workaround is just stopping and starting my tmux sessions when i need to change environment.

like image 744
Phluks Avatar asked Dec 27 '11 13:12

Phluks


People also ask

How do I start tmux automatically?

To configure your terminal to automatically start tmux as default, add the following lines to your ~/. bash_profile shell startup file, just above your aliases section. Save the file and close it. Then close and reopen the terminal to start using tmux by default, every time you open a terminal window.

How do I open an existing tmux session?

Using the Prefixes to Control Tmux By default, the prefix is CTRL+B. That is, we have to press the keys CTRL+B and then the command. For example, to create a new session, the command would be C. So, to create a new session we need to press CTRL+B and next C – CTRL+B, C.

Does tmux inherit environment?

It gives the option to set tmux as the default shell, and spawn it directly. This way tmux does not inherit environment variables from shells.


1 Answers

You should configure the tmux session option update-environment to include the variables you want to be updated when creating new sessions. The default value includes several common X11 and SSH variables:

DISPLAY SSH_ASKPASS SSH_AUTH_SOCK SSH_AGENT_PID SSH_CONNECTION WINDOWID XAUTHORITY 

To add your variables, use the set-option tmux command with its -g and -a flags (append to the existing “global” (default) value). In your ~/.tmux.conf:

set-option -ga update-environment ' YOUR_VAR' 

Be sure to include the leading space so that your variable name is separated from the trailing name in the default value.

like image 177
Chris Johnsen Avatar answered Oct 27 '22 20:10

Chris Johnsen