Prevent fish from re-importing an exported fish_user_paths

fish_user_paths is a fish-specific variable that can be persisted by
making it a universal variable or by making it a global variable set at
startup in `config.fish`.

Since it is not defined in a clean installation, a user could
inadvertently create it as `set -Ux fish_user_paths ....` the first
time, creating a horrible, ugly, self-loathing mess that will have you
chasing ghosts and bisecting for naught once fish re-imports
fish_user_paths as a *global* variable that shadows the universal one.

While that is true for any universal variable that is re-imported as a
global variable, only fish_user_paths has the potential to really screw
things up because we also re-export PATH based off of its value in turn.
This commit is contained in:
Mahmoud Al-Qudsi 2020-10-25 21:45:45 -05:00
parent cbc40842e2
commit 332287708b

View file

@ -257,7 +257,12 @@ void env_init(const struct config_paths_t *paths /* or NULL */) {
key.assign(key_and_val, 0, eql);
val.assign(key_and_val, eql + 1, wcstring::npos);
if (!electric_var_t::for_name(key)) {
vars.set(key, ENV_EXPORT | ENV_GLOBAL, {val});
// fish_user_paths should not be exported; attempting to re-import it from
// a value we previously (due to user error) exported will cause impossibly
// difficult to debug PATH problems.
if (key != L"fish_user_paths") {
vars.set(key, ENV_EXPORT | ENV_GLOBAL, {val});
}
}
}
}