mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-24 05:41:14 -03:00
Add new functions flag -V/--inherit-variable
--inherit-variable takes a variable name and snapshots its current value. When the function is executed, it will have a local variable with this value already defined. Printing the function source will include synthesized `set -l` lines for the values. This is primarily useful for functions that are created on the fly, such as in `psub`.
This commit is contained in:
7
exec.cpp
7
exec.cpp
@@ -856,6 +856,7 @@ void exec_job(parser_t &parser, job_t *j)
|
||||
|
||||
wcstring_list_t named_arguments = function_get_named_arguments(p->argv0());
|
||||
bool shadows = function_get_shadows(p->argv0());
|
||||
std::map<wcstring,env_var_t> inherit_vars = function_get_inherit_vars(p->argv0());
|
||||
|
||||
signal_block();
|
||||
|
||||
@@ -868,12 +869,16 @@ void exec_job(parser_t &parser, job_t *j)
|
||||
parser.push_block(newv);
|
||||
|
||||
/*
|
||||
set_argv might trigger an event
|
||||
setting variables might trigger an event
|
||||
handler, hence we need to unblock
|
||||
signals.
|
||||
*/
|
||||
signal_unblock();
|
||||
parse_util_set_argv(p->get_argv()+1, named_arguments);
|
||||
for (std::map<wcstring,env_var_t>::const_iterator it = inherit_vars.begin(), end = inherit_vars.end(); it != end; ++it)
|
||||
{
|
||||
env_set(it->first, it->second.missing() ? NULL : it->second.c_str(), ENV_LOCAL | ENV_USER);
|
||||
}
|
||||
signal_block();
|
||||
|
||||
parser.forbid_function(p->argv0());
|
||||
|
||||
Reference in New Issue
Block a user