From 7d06e427ffcccef73247157790f67e8c281b1eca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9F=8F=B4=E2=80=8D=E2=98=A0=EF=B8=8F?= <224304+skull-squadron@users.noreply.github.com> Date: Mon, 7 Jul 2025 00:07:07 -0500 Subject: [PATCH] Fix default prompt not showing ~ as ~. Prompt previously showed absolute path instead of `~`. --- src/prompt/default.rs | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/src/prompt/default.rs b/src/prompt/default.rs index f56ae903..def09824 100644 --- a/src/prompt/default.rs +++ b/src/prompt/default.rs @@ -116,21 +116,17 @@ impl DefaultPrompt { } fn get_working_dir() -> Result { - let path = env::current_dir()?; - let path_str = path.display().to_string(); - let homedir: String = match env::var("USERPROFILE") { - Ok(win_home) => win_home, - Err(_) => match env::var("HOME") { - Ok(maclin_home) => maclin_home, - Err(_) => path_str.clone(), - }, - }; - let new_path = if path_str != homedir { - path_str.replace(&homedir, "~") - } else { - path_str - }; - Ok(new_path) + let mut path = env::current_dir()?; + + if let Some(home) = env::home_dir() { + if let Ok(suffix) = path.clone().strip_prefix(home) { + path = std::path::PathBuf::from("~"); + if !suffix.as_os_str().is_empty() { + path = path.join(suffix); + } + } + } + Ok(path.display().to_string()) } fn get_now() -> String {