Add an optional mode to env_get_string()

The mode restricts the scope in which the variable is searched for.

Use this new restricted scope functionality in the `set` builtin. This
fixes `set -g` to not show local shadowing variable values, and also
allows for scoped erasing of slices.
This commit is contained in:
Kevin Ballard
2014-07-12 14:40:46 -07:00
parent 2457997cd9
commit dcc043df3b
4 changed files with 97 additions and 79 deletions

9
env.h
View File

@@ -169,8 +169,13 @@ class env_var_t : public wcstring
};
/** Gets the variable with the specified name, or env_var_t::missing_var if it does not exist. */
env_var_t env_get_string(const wcstring &key);
/**
Gets the variable with the specified name, or env_var_t::missing_var if it does not exist.
\param key The name of the variable to get
\param mode An optional scope to search in. All scopes are searched if unset
*/
env_var_t env_get_string(const wcstring &key, int mode = 0);
/**
Returns true if the specified key exists. This can't be reliably done