aboutsummaryrefslogtreecommitdiffhomepage
path: root/builtin_set.cpp
diff options
context:
space:
mode:
authorGravatar Kevin Ballard <kevin@sb.org>2014-07-12 14:40:46 -0700
committerGravatar Kevin Ballard <kevin@sb.org>2014-07-12 15:35:34 -0700
commitdcc043df3b4d3f2f8aae5d8e8fe50051f78ce848 (patch)
treeec71da325775526d617e946bef394210154176c3 /builtin_set.cpp
parent2457997cd9c624034f28f1be218f93cdc60a3e58 (diff)
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.
Diffstat (limited to 'builtin_set.cpp')
-rw-r--r--builtin_set.cpp16
1 files changed, 4 insertions, 12 deletions
diff --git a/builtin_set.cpp b/builtin_set.cpp
index aae87550..e74cc6d6 100644
--- a/builtin_set.cpp
+++ b/builtin_set.cpp
@@ -69,7 +69,7 @@ static int my_env_set(const wchar_t *key, const wcstring_list_t &val, int scope)
/* Don't bother validating (or complaining about) values that are already present */
wcstring_list_t existing_values;
- const env_var_t existing_variable = env_get_string(key);
+ const env_var_t existing_variable = env_get_string(key, scope);
if (! existing_variable.missing_or_empty())
tokenize_variable_array(existing_variable, existing_values);
@@ -360,7 +360,7 @@ static void print_variables(int include_values, int esc, bool shorten_ok, int sc
if (include_values)
{
- env_var_t value = env_get_string(key);
+ env_var_t value = env_get_string(key, scope);
if (!value.missing())
{
int shorten = 0;
@@ -606,7 +606,7 @@ static int builtin_set(parser_t &parser, wchar_t **argv)
wcstring_list_t result;
size_t j;
- env_var_t dest_str = env_get_string(dest);
+ env_var_t dest_str = env_get_string(dest, scope);
if (! dest_str.missing())
tokenize_variable_array(dest_str, result);
@@ -696,14 +696,6 @@ static int builtin_set(parser_t &parser, wchar_t **argv)
return 1;
}
- if (slice && erase && (scope != ENV_USER))
- {
- free(dest);
- append_format(stderr_buffer, _(L"%ls: Can not specify scope when erasing array slice\n"), argv[0]);
- builtin_print_help(parser, argv[0], stderr_buffer);
- return 1;
- }
-
/*
set assignment can work in two modes, either using slices or
using the whole array. We detect which mode is used here.
@@ -718,7 +710,7 @@ static int builtin_set(parser_t &parser, wchar_t **argv)
std::vector<long> indexes;
wcstring_list_t result;
- const env_var_t dest_str = env_get_string(dest);
+ const env_var_t dest_str = env_get_string(dest, scope);
if (! dest_str.missing())
tokenize_variable_array(dest_str, result);