mirror of
https://github.com/fish-shell/fish-shell
synced 2024-11-15 09:27:38 +00:00
Instance env_set_argv and env_set_pwd
This commit is contained in:
parent
5055621e02
commit
ede66ccaac
7 changed files with 24 additions and 22 deletions
|
@ -86,6 +86,6 @@ int builtin_cd(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||||
return STATUS_CMD_ERROR;
|
return STATUS_CMD_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
env_set_one(L"PWD", ENV_EXPORT | ENV_GLOBAL, std::move(norm_dir));
|
parser.vars().set_one(L"PWD", ENV_EXPORT | ENV_GLOBAL, std::move(norm_dir));
|
||||||
return STATUS_CMD_OK;
|
return STATUS_CMD_OK;
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,7 +78,7 @@ int builtin_source(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||||
|
|
||||||
// This is slightly subtle. If this is a bare `source` with no args then `argv + optind` already
|
// This is slightly subtle. If this is a bare `source` with no args then `argv + optind` already
|
||||||
// points to the end of argv. Otherwise we want to skip the file name to get to the args if any.
|
// points to the end of argv. Otherwise we want to skip the file name to get to the args if any.
|
||||||
env_set_argv(argv + optind + (argc == optind ? 0 : 1));
|
parser.vars().set_argv(argv + optind + (argc == optind ? 0 : 1));
|
||||||
|
|
||||||
retval = reader_read(fd, streams.io_chain ? *streams.io_chain : io_chain_t());
|
retval = reader_read(fd, streams.io_chain ? *streams.io_chain : io_chain_t());
|
||||||
|
|
||||||
|
|
23
src/env.cpp
23
src/env.cpp
|
@ -642,11 +642,11 @@ static void setup_path() {
|
||||||
/// If they don't already exist initialize the `COLUMNS` and `LINES` env vars to reasonable
|
/// If they don't already exist initialize the `COLUMNS` and `LINES` env vars to reasonable
|
||||||
/// defaults. They will be updated later by the `get_current_winsize()` function if they need to be
|
/// defaults. They will be updated later by the `get_current_winsize()` function if they need to be
|
||||||
/// adjusted.
|
/// adjusted.
|
||||||
static void env_set_termsize() {
|
void env_stack_t::set_termsize() {
|
||||||
auto cols = env_get(L"COLUMNS");
|
auto cols = get(L"COLUMNS");
|
||||||
if (cols.missing_or_empty()) env_set_one(L"COLUMNS", ENV_GLOBAL, DFLT_TERM_COL_STR);
|
if (cols.missing_or_empty()) env_set_one(L"COLUMNS", ENV_GLOBAL, DFLT_TERM_COL_STR);
|
||||||
|
|
||||||
auto rows = env_get(L"LINES");
|
auto rows = get(L"LINES");
|
||||||
if (rows.missing_or_empty()) env_set_one(L"LINES", ENV_GLOBAL, DFLT_TERM_ROW_STR);
|
if (rows.missing_or_empty()) env_set_one(L"LINES", ENV_GLOBAL, DFLT_TERM_ROW_STR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -708,8 +708,6 @@ static void setup_user(bool force) {
|
||||||
/// Various things we need to initialize at run-time that don't really fit any of the other init
|
/// Various things we need to initialize at run-time that don't really fit any of the other init
|
||||||
/// routines.
|
/// routines.
|
||||||
void misc_init() {
|
void misc_init() {
|
||||||
env_set_read_limit();
|
|
||||||
|
|
||||||
// If stdout is open on a tty ensure stdio is unbuffered. That's because those functions might
|
// If stdout is open on a tty ensure stdio is unbuffered. That's because those functions might
|
||||||
// be intermixed with `write()` calls and we need to ensure the writes are not reordered. See
|
// be intermixed with `write()` calls and we need to ensure the writes are not reordered. See
|
||||||
// issue #3748.
|
// issue #3748.
|
||||||
|
@ -976,21 +974,22 @@ void env_init(const struct config_paths_t *paths /* or NULL */) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
env_stack_t &vars = env_stack_t::principal();
|
||||||
// initialize the PWD variable if necessary
|
// initialize the PWD variable if necessary
|
||||||
// Note we may inherit a virtual PWD that doesn't match what getcwd would return; respect that.
|
// Note we may inherit a virtual PWD that doesn't match what getcwd would return; respect that.
|
||||||
if (env_get(L"PWD").missing_or_empty()) {
|
if (vars.get(L"PWD").missing_or_empty()) {
|
||||||
env_stack_t::principal().set_pwd_from_getcwd();
|
vars.set_pwd_from_getcwd();
|
||||||
}
|
}
|
||||||
env_set_termsize(); // initialize the terminal size variables
|
vars.set_termsize(); // initialize the terminal size variables
|
||||||
env_set_read_limit(); // initialize the read_byte_limit
|
vars.set_read_limit(); // initialize the read_byte_limit
|
||||||
|
|
||||||
// Set g_use_posix_spawn. Default to true.
|
// Set g_use_posix_spawn. Default to true.
|
||||||
auto use_posix_spawn = env_get(L"fish_use_posix_spawn");
|
auto use_posix_spawn = vars.get(L"fish_use_posix_spawn");
|
||||||
g_use_posix_spawn =
|
g_use_posix_spawn =
|
||||||
use_posix_spawn.missing_or_empty() ? true : from_string<bool>(use_posix_spawn->as_string());
|
use_posix_spawn.missing_or_empty() ? true : from_string<bool>(use_posix_spawn->as_string());
|
||||||
|
|
||||||
// Set fish_bind_mode to "default".
|
// Set fish_bind_mode to "default".
|
||||||
env_set_one(FISH_BIND_MODE_VAR, ENV_GLOBAL, DEFAULT_BIND_MODE);
|
vars.set_one(FISH_BIND_MODE_VAR, ENV_GLOBAL, DEFAULT_BIND_MODE);
|
||||||
|
|
||||||
// This is somewhat subtle. At this point we consider our environment to be sufficiently
|
// This is somewhat subtle. At this point we consider our environment to be sufficiently
|
||||||
// initialized that we can react to changes to variables. Prior to doing this we expect that the
|
// initialized that we can react to changes to variables. Prior to doing this we expect that the
|
||||||
|
@ -1440,8 +1439,6 @@ int env_remove(const wcstring &key, int mode) { return env_stack_t::principal().
|
||||||
|
|
||||||
void env_universal_barrier() { env_stack_t::principal().universal_barrier(); }
|
void env_universal_barrier() { env_stack_t::principal().universal_barrier(); }
|
||||||
|
|
||||||
void env_set_argv(const wchar_t *const *argv) { return env_stack_t::principal().set_argv(argv); }
|
|
||||||
|
|
||||||
wcstring env_get_pwd_slash() { return env_stack_t::principal().get_pwd_slash(); }
|
wcstring env_get_pwd_slash() { return env_stack_t::principal().get_pwd_slash(); }
|
||||||
|
|
||||||
void env_set_read_limit() { return env_stack_t::principal().set_read_limit(); }
|
void env_set_read_limit() { return env_stack_t::principal().set_read_limit(); }
|
||||||
|
|
|
@ -168,9 +168,6 @@ int env_remove(const wcstring &key, int mode);
|
||||||
/// Synchronizes all universal variable changes: writes everything out, reads stuff in.
|
/// Synchronizes all universal variable changes: writes everything out, reads stuff in.
|
||||||
void env_universal_barrier();
|
void env_universal_barrier();
|
||||||
|
|
||||||
/// Sets up argv as the given null terminated array of strings.
|
|
||||||
void env_set_argv(const wchar_t *const *argv);
|
|
||||||
|
|
||||||
/// Returns the PWD with a terminating slash.
|
/// Returns the PWD with a terminating slash.
|
||||||
wcstring env_get_pwd_slash();
|
wcstring env_get_pwd_slash();
|
||||||
|
|
||||||
|
@ -236,6 +233,12 @@ class env_stack_t : public environment_t {
|
||||||
/// Returns all variable names.
|
/// Returns all variable names.
|
||||||
wcstring_list_t get_names(int flags) const override;
|
wcstring_list_t get_names(int flags) const override;
|
||||||
|
|
||||||
|
/// Update the termsize variable.
|
||||||
|
void set_termsize();
|
||||||
|
|
||||||
|
/// Update the PWD variable directory.
|
||||||
|
bool set_pwd();
|
||||||
|
|
||||||
/// Sets up argv as the given null terminated array of strings.
|
/// Sets up argv as the given null terminated array of strings.
|
||||||
void set_argv(const wchar_t *const *argv);
|
void set_argv(const wchar_t *const *argv);
|
||||||
|
|
||||||
|
|
|
@ -787,7 +787,7 @@ static bool exec_block_or_func_process(parser_t &parser, std::shared_ptr<job_t>
|
||||||
|
|
||||||
function_block_t *fb =
|
function_block_t *fb =
|
||||||
parser.push_block<function_block_t>(p, func_name, props->shadow_scope);
|
parser.push_block<function_block_t>(p, func_name, props->shadow_scope);
|
||||||
function_prepare_environment(func_name, p->get_argv() + 1, inherit_vars);
|
function_prepare_environment(parser.vars(), func_name, p->get_argv() + 1, inherit_vars);
|
||||||
parser.forbid_function(func_name);
|
parser.forbid_function(func_name);
|
||||||
|
|
||||||
internal_exec_helper(parser, props->parsed_source, props->body_node, io_chain, j);
|
internal_exec_helper(parser, props->parsed_source, props->body_node, io_chain, j);
|
||||||
|
|
|
@ -344,9 +344,10 @@ void function_invalidate_path() { function_autoloader.invalidate(); }
|
||||||
// 1. argv
|
// 1. argv
|
||||||
// 2. named arguments
|
// 2. named arguments
|
||||||
// 3. inherited variables
|
// 3. inherited variables
|
||||||
void function_prepare_environment(const wcstring &name, const wchar_t *const *argv,
|
void function_prepare_environment(env_stack_t &vars, const wcstring &name,
|
||||||
|
const wchar_t *const *argv,
|
||||||
const std::map<wcstring, env_var_t> &inherited_vars) {
|
const std::map<wcstring, env_var_t> &inherited_vars) {
|
||||||
env_set_argv(argv);
|
vars.set_argv(argv);
|
||||||
auto props = function_get_properties(name);
|
auto props = function_get_properties(name);
|
||||||
if (props && !props->named_arguments.empty()) {
|
if (props && !props->named_arguments.empty()) {
|
||||||
const wchar_t *const *arg = argv;
|
const wchar_t *const *arg = argv;
|
||||||
|
|
|
@ -109,7 +109,8 @@ std::map<wcstring, env_var_t> function_get_inherit_vars(const wcstring &name);
|
||||||
bool function_copy(const wcstring &name, const wcstring &new_name);
|
bool function_copy(const wcstring &name, const wcstring &new_name);
|
||||||
|
|
||||||
/// Prepares the environment for executing a function.
|
/// Prepares the environment for executing a function.
|
||||||
void function_prepare_environment(const wcstring &name, const wchar_t *const *argv,
|
void function_prepare_environment(env_stack_t &vars, const wcstring &name,
|
||||||
|
const wchar_t *const *argv,
|
||||||
const std::map<wcstring, env_var_t> &inherited_vars);
|
const std::map<wcstring, env_var_t> &inherited_vars);
|
||||||
|
|
||||||
/// Observes that fish_function_path has changed.
|
/// Observes that fish_function_path has changed.
|
||||||
|
|
Loading…
Reference in a new issue