mirror of
https://github.com/jbranchaud/til
synced 2026-01-03 15:18:01 +00:00
Add Set Session-Specific Environment Variables as a tmux til
This commit is contained in:
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
|
|||||||
|
|
||||||
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
|
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
|
||||||
|
|
||||||
_1175 TILs and counting..._
|
_1176 TILs and counting..._
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -1061,6 +1061,7 @@ _1175 TILs and counting..._
|
|||||||
- [Remove The Delay On The Escape Key](tmux/remove-the-delay-on-the-escape-key.md)
|
- [Remove The Delay On The Escape Key](tmux/remove-the-delay-on-the-escape-key.md)
|
||||||
- [Rename The Current Session](tmux/rename-the-current-session.md)
|
- [Rename The Current Session](tmux/rename-the-current-session.md)
|
||||||
- [Reset An Option Back To Its Default Value](tmux/reset-an-option-back-to-its-default-value.md)
|
- [Reset An Option Back To Its Default Value](tmux/reset-an-option-back-to-its-default-value.md)
|
||||||
|
- [Set Session Specific Environment Variables](tmux/set-session-specific-environment-variables.md)
|
||||||
- [Show The Current Value For An Option](tmux/show-the-current-value-for-an-option.md)
|
- [Show The Current Value For An Option](tmux/show-the-current-value-for-an-option.md)
|
||||||
- [Swap Split Panes](tmux/swap-split-panes.md)
|
- [Swap Split Panes](tmux/swap-split-panes.md)
|
||||||
- [Switch To A Specific Session And Window](tmux/switch-to-a-specific-session-and-window.md)
|
- [Switch To A Specific Session And Window](tmux/switch-to-a-specific-session-and-window.md)
|
||||||
|
|||||||
51
tmux/set-session-specific-environment-variables.md
Normal file
51
tmux/set-session-specific-environment-variables.md
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
# 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.
|
||||||
Reference in New Issue
Block a user