Get $nu.config-path and $nu.env-path from EngineState (#6366)

* Get `$nu.config-path` and `$nu.env-path` from `EngineState`

Signed-off-by: nibon7 <nibon7@163.com>

* replace tuple with hashmap

Signed-off-by: nibon7 <nibon7@163.com>

* refactor set_config_path

Signed-off-by: nibon7 <nibon7@163.com>

Signed-off-by: nibon7 <nibon7@163.com>
This commit is contained in:
nibon7
2022-08-23 00:30:09 +08:00
committed by GitHub
parent 9c4bbe3c63
commit 772ad896c8
3 changed files with 83 additions and 13 deletions

View File

@ -1298,6 +1298,22 @@ pub fn eval_variable(
let mut output_cols = vec![];
let mut output_vals = vec![];
if let Some(path) = engine_state.get_config_path("config-path") {
output_cols.push("config-path".into());
output_vals.push(Value::String {
val: path.to_string_lossy().to_string(),
span,
});
}
if let Some(path) = engine_state.get_config_path("env-path") {
output_cols.push("env-path".into());
output_vals.push(Value::String {
val: path.to_string_lossy().to_string(),
span,
});
}
if let Some(mut config_path) = nu_path::config_dir() {
config_path.push("nushell");
let mut env_config_path = config_path.clone();
@ -1321,21 +1337,25 @@ pub fn eval_variable(
span,
});
config_path.push("config.nu");
if engine_state.get_config_path("config-path").is_none() {
config_path.push("config.nu");
output_cols.push("config-path".into());
output_vals.push(Value::String {
val: config_path.to_string_lossy().to_string(),
span,
});
output_cols.push("config-path".into());
output_vals.push(Value::String {
val: config_path.to_string_lossy().to_string(),
span,
});
}
env_config_path.push("env.nu");
if engine_state.get_config_path("env-path").is_none() {
env_config_path.push("env.nu");
output_cols.push("env-path".into());
output_vals.push(Value::String {
val: env_config_path.to_string_lossy().to_string(),
span,
});
output_cols.push("env-path".into());
output_vals.push(Value::String {
val: env_config_path.to_string_lossy().to_string(),
span,
});
}
loginshell_path.push("login.nu");