From ff37975452d4cbc8a3f117baa9444f3fd023bd66 Mon Sep 17 00:00:00 2001 From: NerdyPepper Date: Tue, 9 Jul 2019 22:56:27 +0530 Subject: handle edge cases --- src/cwd.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/cwd.rs b/src/cwd.rs index 7672981..95b6659 100644 --- a/src/cwd.rs +++ b/src/cwd.rs @@ -8,7 +8,11 @@ pub fn cwd() -> colored::ColoredString { let tilde_expand = env::var("EXPAND_TILDE").unwrap_or("0".into()); match tilde_expand.as_ref() { - "0" => path = path.replace(&home[..], "~"), + "0" => { + if (&path[..]).starts_with(&home[..]) && home.len() > 0 { + path = path.replacen(&home[..], "~", 1); + } + } _ => {} }; -- cgit v1.2.3