diff options
Diffstat (limited to 'src/cwd.rs')
-rw-r--r-- | src/cwd.rs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/cwd.rs b/src/cwd.rs new file mode 100644 index 0000000..8f1f86a --- /dev/null +++ b/src/cwd.rs | |||
@@ -0,0 +1,22 @@ | |||
1 | use std::env; | ||
2 | use tico::tico; | ||
3 | use colored::*; | ||
4 | |||
5 | pub fn cwd() -> colored::ColoredString { | ||
6 | let mut path = env::var("PWD").unwrap(); | ||
7 | let home = env::var("HOME").unwrap(); | ||
8 | let tilde_expand = env::var("EXPAND_TILDE").unwrap_or("0".into()); | ||
9 | |||
10 | match tilde_expand.as_ref() { | ||
11 | "0" => {}, | ||
12 | _ => path = path.replace(&home[..], "~") | ||
13 | }; | ||
14 | |||
15 | let cwd_shorten = env::var("SHORTEN_CWD").unwrap_or("1".into()); | ||
16 | let cwd_color = env::var("CWD_COLOR").unwrap_or("white".into()); | ||
17 | match cwd_shorten.as_ref() { | ||
18 | "0" => return path.color(cwd_color), | ||
19 | _ => return tico(&path[..]).color(cwd_color) | ||
20 | } | ||
21 | |||
22 | } | ||