diff --git a/src/config_files.rs b/src/config_files.rs index 847ecfa020..18a2586fd7 100644 --- a/src/config_files.rs +++ b/src/config_files.rs @@ -2,7 +2,7 @@ use log::info; use nu_cli::{eval_config_contents, eval_source, report_error}; use nu_parser::ParseError; 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 std::fs::File; use std::io::Write; @@ -121,3 +121,37 @@ pub(crate) fn read_loginshell_file( 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); + } + } +} diff --git a/src/main.rs b/src/main.rs index 0733ff14a9..ece58ae0e8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -215,6 +215,12 @@ fn main() -> Result<()> { is_perf_true(), true, ); + } else { + config_files::read_default_env_file( + &mut engine_state, + &mut stack, + is_perf_true(), + ) } if binary_args.config_file.is_some() { @@ -262,6 +268,12 @@ fn main() -> Result<()> { is_perf_true(), true, ); + } else { + config_files::read_default_env_file( + &mut engine_state, + &mut stack, + is_perf_true(), + ) } if binary_args.config_file.is_some() {