Skip to content

Commit 7d06e42

Browse files
Fix default prompt not showing ~ as ~.
Prompt previously showed absolute path instead of `~`.
1 parent e4221b9 commit 7d06e42

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

src/prompt/default.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -116,21 +116,17 @@ impl DefaultPrompt {
116116
}
117117

118118
fn get_working_dir() -> Result<String, std::io::Error> {
119-
let path = env::current_dir()?;
120-
let path_str = path.display().to_string();
121-
let homedir: String = match env::var("USERPROFILE") {
122-
Ok(win_home) => win_home,
123-
Err(_) => match env::var("HOME") {
124-
Ok(maclin_home) => maclin_home,
125-
Err(_) => path_str.clone(),
126-
},
127-
};
128-
let new_path = if path_str != homedir {
129-
path_str.replace(&homedir, "~")
130-
} else {
131-
path_str
132-
};
133-
Ok(new_path)
119+
let mut path = env::current_dir()?;
120+
121+
if let Some(home) = env::home_dir() {
122+
if let Ok(suffix) = path.clone().strip_prefix(home) {
123+
path = std::path::PathBuf::from("~");
124+
if !suffix.as_os_str().is_empty() {
125+
path = path.join(suffix);
126+
}
127+
}
128+
}
129+
Ok(path.display().to_string())
134130
}
135131

136132
fn get_now() -> String {

0 commit comments

Comments
 (0)