From 0eabbb88dd3ec6fc2a82228f42a0d88678e8ff19 Mon Sep 17 00:00:00 2001 From: Aakash parmar <94752702+Aakash788@users.noreply.github.com> Date: Mon, 12 Aug 2024 20:13:59 +0530 Subject: [PATCH] Replace only leading home path with `~` in the title (#13600) # Description : - This pull request addresses issue #13594 where any substring of the path that matches the home directory is replaced with `~` in the title bar. This was problematic because partial matches within the path were also being replaced. --------- Signed-off-by: Aakash788 Co-authored-by: sholderbach --- crates/nu-cli/src/repl.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/crates/nu-cli/src/repl.rs b/crates/nu-cli/src/repl.rs index 28a3e2cec7..1cb6f005ef 100644 --- a/crates/nu-cli/src/repl.rs +++ b/crates/nu-cli/src/repl.rs @@ -911,7 +911,12 @@ fn run_shell_integration_osc2( // Try to abbreviate string for windows title let maybe_abbrev_path = if let Some(p) = nu_path::home_dir() { - path.replace(&p.as_path().display().to_string(), "~") + let home_dir_str = p.as_path().display().to_string(); + if path.starts_with(&home_dir_str) { + path.replacen(&home_dir_str, "~", 1) + } else { + path + } } else { path };