From 74d3b10a01321b34bd5e26ef456d6b4d201b062e Mon Sep 17 00:00:00 2001 From: NerdyPepper Date: Fri, 12 Jul 2019 14:54:44 +0530 Subject: improve output in non existent directories --- src/cwd.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/cwd.rs') diff --git a/src/cwd.rs b/src/cwd.rs index 95b6659..157858c 100644 --- a/src/cwd.rs +++ b/src/cwd.rs @@ -2,8 +2,9 @@ use std::env; use tico::tico; use colored::*; -pub fn cwd() -> colored::ColoredString { - let mut path = format!("{}", env::current_dir().unwrap_or("".into()).display()); +pub fn cwd() -> Option { + let path_env = env::current_dir().ok()?; + let mut path = format!("{}", path_env.display()); let home = env::var("HOME").unwrap(); let tilde_expand = env::var("EXPAND_TILDE").unwrap_or("0".into()); @@ -19,8 +20,8 @@ pub fn cwd() -> colored::ColoredString { let cwd_shorten = env::var("SHORTEN_CWD").unwrap_or("1".into()); let cwd_color = env::var("CWD_COLOR").unwrap_or("white".into()); match cwd_shorten.as_ref() { - "0" => return path.color(cwd_color), - _ => return tico(&path[..]).color(cwd_color) + "0" => return Some(path.color(cwd_color)), + _ => return Some(tico(&path[..]).color(cwd_color)) } } -- cgit v1.2.3