mirror of
https://github.com/nushell/nushell.git
synced 2025-05-31 23:26:11 +02:00
load default env when user don't specified env path (#6040)
This commit is contained in:
parent
ceafe434b5
commit
ed50210832
@ -2,7 +2,7 @@ use log::info;
|
|||||||
use nu_cli::{eval_config_contents, eval_source, report_error};
|
use nu_cli::{eval_config_contents, eval_source, report_error};
|
||||||
use nu_parser::ParseError;
|
use nu_parser::ParseError;
|
||||||
use nu_path::canonicalize_with;
|
use nu_path::canonicalize_with;
|
||||||
use nu_protocol::engine::{EngineState, Stack, StateWorkingSet};
|
use nu_protocol::engine::{EngineState, Stack, StateDelta, StateWorkingSet};
|
||||||
use nu_protocol::{PipelineData, Span, Spanned};
|
use nu_protocol::{PipelineData, Span, Spanned};
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
@ -121,3 +121,37 @@ pub(crate) fn read_loginshell_file(
|
|||||||
info!("read_loginshell_file {}:{}:{}", file!(), line!(), column!());
|
info!("read_loginshell_file {}:{}:{}", file!(), line!(), column!());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn read_default_env_file(
|
||||||
|
engine_state: &mut EngineState,
|
||||||
|
stack: &mut Stack,
|
||||||
|
is_perf_true: bool,
|
||||||
|
) {
|
||||||
|
let config_file = include_str!("../docs/sample_config/default_env.nu");
|
||||||
|
eval_source(
|
||||||
|
engine_state,
|
||||||
|
stack,
|
||||||
|
config_file.as_bytes(),
|
||||||
|
"default_env.nu",
|
||||||
|
PipelineData::new(Span::new(0, 0)),
|
||||||
|
);
|
||||||
|
|
||||||
|
if is_perf_true {
|
||||||
|
info!("read_config_file {}:{}:{}", file!(), line!(), column!());
|
||||||
|
}
|
||||||
|
// Merge the delta in case env vars changed in the config
|
||||||
|
match nu_engine::env::current_dir(engine_state, stack) {
|
||||||
|
Ok(cwd) => {
|
||||||
|
if let Err(e) =
|
||||||
|
engine_state.merge_delta(StateDelta::new(engine_state), Some(stack), cwd)
|
||||||
|
{
|
||||||
|
let working_set = StateWorkingSet::new(engine_state);
|
||||||
|
report_error(&working_set, &e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
let working_set = StateWorkingSet::new(engine_state);
|
||||||
|
report_error(&working_set, &e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
12
src/main.rs
12
src/main.rs
@ -215,6 +215,12 @@ fn main() -> Result<()> {
|
|||||||
is_perf_true(),
|
is_perf_true(),
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
config_files::read_default_env_file(
|
||||||
|
&mut engine_state,
|
||||||
|
&mut stack,
|
||||||
|
is_perf_true(),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if binary_args.config_file.is_some() {
|
if binary_args.config_file.is_some() {
|
||||||
@ -262,6 +268,12 @@ fn main() -> Result<()> {
|
|||||||
is_perf_true(),
|
is_perf_true(),
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
config_files::read_default_env_file(
|
||||||
|
&mut engine_state,
|
||||||
|
&mut stack,
|
||||||
|
is_perf_true(),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if binary_args.config_file.is_some() {
|
if binary_args.config_file.is_some() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user