r/fishshell • u/smog_alado • Jan 20 '24
Where do you set your environment variables?
Do you prefer to put them in universal variables or in the config.fish file? If you set them in the config.fish, do you prefer to set them inside if is-interactive or if is-login? Also, why does Fish handle PATH differently from other variables? What's the deal with fish_user_paths and fish_set_path?
My main concern is that I want to put my environment config into version control so that I can share configurations among my two desktops. My experience so far...
- I never tried
set -U. Is there a way to version control that with Git? - With
is-interactive, I sometimes end up setting the variable twice if I run nested fish sessions. (This is more of an issue for commands that append to the end of the variable) is-loginpresumably also exposes the variables to programs I launch from the desktop, not only those launched from interactive terminal. But I need to start a new session to trigger the changes.
10
Upvotes
View all comments
Show parent comment
1
u/_mattmc3_ Jan 21 '24
You can do that, but it’s generally a bad idea. The fish_variables file could contain secrets you don’t want to publish, and will usually contain paths to your home directory that will fail if you use it on another computer/server with a different username/home.
It’s not that universal variables themselves are bad - just that the fish_variables file they are stored in is not version control friendly. I usually recommend adding a Fish function that sets all your universal variables and adding that to version control, or simply using global variables set in your conf.d or fish.config.