From 7a61286a9fdbf691b2dd15adf040a6ac6f22eff3 Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Mon, 3 Jan 2022 13:06:54 -0600 Subject: [PATCH] Add Set Session-Specific Environment Variables as a tmux til --- README.md | 3 +- ...-session-specific-environment-variables.md | 51 +++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 tmux/set-session-specific-environment-variables.md diff --git a/README.md b/README.md index 9ca9278..3c07845 100644 --- a/README.md +++ b/README.md @@ -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). -_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) - [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) +- [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) - [Swap Split Panes](tmux/swap-split-panes.md) - [Switch To A Specific Session And Window](tmux/switch-to-a-specific-session-and-window.md) diff --git a/tmux/set-session-specific-environment-variables.md b/tmux/set-session-specific-environment-variables.md new file mode 100644 index 0000000..bc40dd4 --- /dev/null +++ b/tmux/set-session-specific-environment-variables.md @@ -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 +: +: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.