diff --git a/crates/nu-cli/src/repl.rs b/crates/nu-cli/src/repl.rs index 13837880b..1fd60a16b 100644 --- a/crates/nu-cli/src/repl.rs +++ b/crates/nu-cli/src/repl.rs @@ -12,7 +12,7 @@ use nu_color_config::StyleComputer; use nu_command::hook::eval_hook; use nu_command::util::get_guaranteed_cwd; use nu_engine::convert_env_values; -use nu_parser::{lex, trim_quotes_str}; +use nu_parser::{lex, parse, trim_quotes_str}; use nu_protocol::{ config::NuCursorShape, engine::{EngineState, Stack, StateWorkingSet}, @@ -591,6 +591,27 @@ pub fn evaluate_repl( } else if !s.trim().is_empty() { trace!("eval source: {}", s); + let mut cmds = s.split_whitespace(); + if let Some("exit") = cmds.next() { + let mut working_set = StateWorkingSet::new(engine_state); + let _ = parse(&mut working_set, None, s.as_bytes(), false); + + if working_set.parse_errors.is_empty() { + match cmds.next() { + Some(s) => { + if let Ok(n) = s.parse::() { + drop(line_editor); + std::process::exit(n); + } + } + None => { + drop(line_editor); + std::process::exit(0); + } + } + } + } + eval_source( engine_state, stack,