Skip to content

Commit

Permalink
Replace only leading home path with ~ in the title (nushell#13600)
Browse files Browse the repository at this point in the history
# Description :
- This pull request addresses issue nushell#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 <[email protected]>
Co-authored-by: sholderbach <[email protected]>
  • Loading branch information
Aakash788 and sholderbach authored Aug 12, 2024
1 parent 80c8edc commit 0eabbb8
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion crates/nu-cli/src/repl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down

0 comments on commit 0eabbb8

Please sign in to comment.