From 53fce2c35efc52e36e587b79afdceb7e68580718 Mon Sep 17 00:00:00 2001 From: NerdyPepper Date: Tue, 6 Aug 2019 21:37:32 +0530 Subject: make changes as @shdown suggested --- src/cwd.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/cwd.rs b/src/cwd.rs index 157858c..c8af68e 100644 --- a/src/cwd.rs +++ b/src/cwd.rs @@ -10,8 +10,10 @@ pub fn cwd() -> Option { match tilde_expand.as_ref() { "0" => { - if (&path[..]).starts_with(&home[..]) && home.len() > 0 { - path = path.replacen(&home[..], "~", 1); + let home_dir = &home.clone(); + let home_dir_ext = format!("{}{}", home_dir, "/"); + if (&path == home_dir) || *(&path.starts_with(&home_dir_ext)) { + path = path.replacen(&home_dir[..], "~", 1); } } _ => {} @@ -21,7 +23,7 @@ pub fn cwd() -> Option { let cwd_color = env::var("CWD_COLOR").unwrap_or("white".into()); match cwd_shorten.as_ref() { "0" => return Some(path.color(cwd_color)), - _ => return Some(tico(&path[..]).color(cwd_color)) + _ => return Some(tico(&path).color(cwd_color)) } } -- cgit v1.2.3