mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-01 13:01:21 -03:00
set: Print an error when setting a special var in the wrong scope
When attempting to set a readonly or electric variable in the local or universal scopes, print an appropriate error. Similarly, print an error when setting an electric variable as exported. In most cases this is simply a nicer error instead of the 'read-only' one, but for the 'umask' variable it prevents `set -l umask 0023` from silently changing the global value.
This commit is contained in:
9
env.cpp
9
env.cpp
@@ -634,6 +634,15 @@ int env_set(const wcstring &key, const wchar_t *val, int var_mode)
|
||||
}
|
||||
}
|
||||
|
||||
if ((var_mode & (ENV_LOCAL | ENV_UNIVERSAL)) && (is_read_only(key) || is_electric(key)))
|
||||
{
|
||||
return ENV_SCOPE;
|
||||
}
|
||||
if ((var_mode & ENV_EXPORT) && is_electric(key))
|
||||
{
|
||||
return ENV_SCOPE;
|
||||
}
|
||||
|
||||
if ((var_mode & ENV_USER) && is_read_only(key))
|
||||
{
|
||||
return ENV_PERM;
|
||||
|
||||
Reference in New Issue
Block a user