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 <aakashparmar788@gmail.com>
Co-authored-by: sholderbach <sholderbach@users.noreply.github.com>
This commit is contained in:
Aakash parmar 2024-08-12 20:13:59 +05:30 committed by GitHub
parent 80c8edcfb4
commit 0eabbb88dd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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
};