diff options
author | Kevin Ballard <kevin@sb.org> | 2014-07-12 01:45:52 -0700 |
---|---|---|
committer | Kevin Ballard <kevin@sb.org> | 2014-07-12 14:07:55 -0700 |
commit | 2eb65b362518fe3407fa6fd759927ef3136ad0a6 (patch) | |
tree | 4a464368a00bb7d1565758735c417cc8497da5c9 /builtin_set.cpp | |
parent | 76fdfe6890ece17c7b54f51f320432bcb3e38c2f (diff) |
set: Don't treat toplevel scope the same as global
When using the `set` command with the -l flag, if we're at the top
level, create a temporary local scope. This makes query/assignment
behavior be consistent with the value-printing behavior.
This works by marking the current block as needing to pop the
environment if a local scope was pushed. I assume this is safe to do. I
also assume the current block is the right one to modify, rather than
trying to walk up the stack to the root.
Diffstat (limited to 'builtin_set.cpp')
-rw-r--r-- | builtin_set.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/builtin_set.cpp b/builtin_set.cpp index 9efd12bc..9068372f 100644 --- a/builtin_set.cpp +++ b/builtin_set.cpp @@ -559,6 +559,17 @@ static int builtin_set(parser_t &parser, wchar_t **argv) */ scope = (local ? ENV_LOCAL : 0) | (global ? ENV_GLOBAL : 0) | (exportv ? ENV_EXPORT : 0) | (unexport ? ENV_UNEXPORT : 0) | (universal ? ENV_UNIVERSAL:0) | ENV_USER; + /* + If we're interacting with the local scope at all, ensure we actually have + one that's distinct from the global scope. If we don't have one yet, + create one and modify the current block to pop it. + */ + if ((scope & ENV_LOCAL) && env_ensure_local_scope()) + { + block_t *block = parser.current_block(); + block->wants_pop_env = true; + } + if (query) { /* |