diff --git a/crates/nu-cli/src/repl.rs b/crates/nu-cli/src/repl.rs index 9d897033edd8a..585a2c55466dc 100644 --- a/crates/nu-cli/src/repl.rs +++ b/crates/nu-cli/src/repl.rs @@ -666,13 +666,16 @@ pub fn evaluate_repl( false, ); } - // we save the duration here, but will actually modify - // the stack later + let cmd_duration = start_time.elapsed(); + stack.add_env_var( + "CMD_DURATION_MS".into(), + Value::string(format!("{}", cmd_duration.as_millis()), Span::unknown()), + ); if history_supports_meta && !s.is_empty() && line_editor.has_last_command_context() { - // not a stack reference because update_last_commandcontext gets called immediately + // not a long-held stack reference because update_last_command_context gets called immediately let stack = stack.child_stack(); line_editor .update_last_command_context(&|mut c| { @@ -746,10 +749,6 @@ pub fn evaluate_repl( repl.buffer = "".to_string(); repl.cursor_pos = 0; drop(repl); - stack.add_env_var( - "CMD_DURATION_MS".into(), - Value::string(format!("{}", cmd_duration.as_millis()), Span::unknown()), - ); } Ok(Signal::CtrlC) => { // `Reedline` clears the line content. New prompt is shown