1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-03 15:18:01 +00:00
Files
til/tmux/set-session-specific-environment-variables.md

52 lines
1.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Set Session-Specific Environment Variables
`tmux` allows you to manage separate environments for separate projects. For me
this usually boils down to arrangements of windows and tabs with different
servers running.
`tmux` can also provide session-specific environment variables. For anything
that you use environment variables for.
As an example, let's say I have one project that I always edit with VS Code.
And another that uses `vim`.
My default editor, as configured in my `~/.zshrc` file is `nvim`.
```bash
echo $EDITOR
nvim
```
If I jump into the first project (`one`), I can set the `EDITOR` to `code` like
so.
```bash
tmux setenv EDITOR code
```
It won't apply to the current pane, but if I open a new one.
```
echo $EDITOR
code
```
I can then jump to the other project (`two`) to set that one to `vim`. This
time using the tmux command prompt.
```bash
<tmux-prefix>:
:setenv EDITOR vim
```
Again, if I open a new pane, the editor will be set.
```
echo $EDITOR
vim
```
All the while, the value of `EDITOR` is preserved as `nvim` for everything
outside the context of those two tmux sessions.