From 152fb5be39dc9e37f3dd5ede2bc7eba11cc6d810 Mon Sep 17 00:00:00 2001 From: YizhePKU Date: Mon, 8 Jul 2024 00:43:22 +0800 Subject: [PATCH] Fix PWD-aware command hints (#13024) This PR fixes PWD-aware command hints by sending PWD to the Reedline state in every REPL loop. This PR should be merged along with https://github.com/nushell/reedline/pull/796. Fixes https://github.com/nushell/nushell/issues/12951. --- crates/nu-cli/src/repl.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/crates/nu-cli/src/repl.rs b/crates/nu-cli/src/repl.rs index 251876022a..d2de8f4bea 100644 --- a/crates/nu-cli/src/repl.rs +++ b/crates/nu-cli/src/repl.rs @@ -336,6 +336,13 @@ fn loop_iteration(ctx: LoopContext) -> (bool, Stack, Reedline) { .with_quick_completions(config.quick_completions) .with_partial_completions(config.partial_completions) .with_ansi_colors(config.use_ansi_coloring) + .with_cwd(Some( + engine_state + .cwd(None) + .unwrap_or_default() + .to_string_lossy() + .to_string(), + )) .with_cursor_config(cursor_config); perf!("reedline builder", start_time, use_color); @@ -666,13 +673,14 @@ fn prepare_history_metadata( line_editor: &mut Reedline, ) { if !s.is_empty() && line_editor.has_last_command_context() { - #[allow(deprecated)] let result = line_editor .update_last_command_context(&|mut c| { c.start_timestamp = Some(chrono::Utc::now()); c.hostname = hostname.map(str::to_string); - - c.cwd = Some(StateWorkingSet::new(engine_state).get_cwd()); + c.cwd = engine_state + .cwd(None) + .ok() + .map(|path| path.to_string_lossy().to_string()); c }) .into_diagnostic();