diff options
author | NerdyPepper <[email protected]> | 2019-07-12 10:24:44 +0100 |
---|---|---|
committer | NerdyPepper <[email protected]> | 2019-07-12 10:24:44 +0100 |
commit | 74d3b10a01321b34bd5e26ef456d6b4d201b062e (patch) | |
tree | 7b0e2b2c080298667a38b74de9fca7372cd4b14b /src/cwd.rs | |
parent | d1847724d79521443e661c50a5c69171910f823c (diff) |
improve output in non existent directories
Diffstat (limited to 'src/cwd.rs')
-rw-r--r-- | src/cwd.rs | 9 |
1 files changed, 5 insertions, 4 deletions
@@ -2,8 +2,9 @@ use std::env; | |||
2 | use tico::tico; | 2 | use tico::tico; |
3 | use colored::*; | 3 | use colored::*; |
4 | 4 | ||
5 | pub fn cwd() -> colored::ColoredString { | 5 | pub fn cwd() -> Option<colored::ColoredString> { |
6 | let mut path = format!("{}", env::current_dir().unwrap_or("".into()).display()); | 6 | let path_env = env::current_dir().ok()?; |
7 | let mut path = format!("{}", path_env.display()); | ||
7 | let home = env::var("HOME").unwrap(); | 8 | let home = env::var("HOME").unwrap(); |
8 | let tilde_expand = env::var("EXPAND_TILDE").unwrap_or("0".into()); | 9 | let tilde_expand = env::var("EXPAND_TILDE").unwrap_or("0".into()); |
9 | 10 | ||
@@ -19,8 +20,8 @@ pub fn cwd() -> colored::ColoredString { | |||
19 | let cwd_shorten = env::var("SHORTEN_CWD").unwrap_or("1".into()); | 20 | let cwd_shorten = env::var("SHORTEN_CWD").unwrap_or("1".into()); |
20 | let cwd_color = env::var("CWD_COLOR").unwrap_or("white".into()); | 21 | let cwd_color = env::var("CWD_COLOR").unwrap_or("white".into()); |
21 | match cwd_shorten.as_ref() { | 22 | match cwd_shorten.as_ref() { |
22 | "0" => return path.color(cwd_color), | 23 | "0" => return Some(path.color(cwd_color)), |
23 | _ => return tico(&path[..]).color(cwd_color) | 24 | _ => return Some(tico(&path[..]).color(cwd_color)) |
24 | } | 25 | } |
25 | 26 | ||
26 | } | 27 | } |