diff options
author | Benjamin Große <[email protected]> | 2021-11-27 19:20:54 +0000 |
---|---|---|
committer | Benjamin Große <[email protected]> | 2021-12-15 11:52:06 +0000 |
commit | e426ee675844c90bea285b4bc8ec9a2cc5c3b4ef (patch) | |
tree | a1f5cf81e4724635ba767d28315dd0b1e06cd83d /src | |
parent | 5b022fa71a26176dabc92afb211ab8f3707c2020 (diff) |
Hides path if in $HOME. It only shows the prompt char, as usually $HOME
has no git repo. Looks pretty cool when opening a new terminal.
Diffstat (limited to 'src')
-rw-r--r-- | src/cwd.rs | 16 | ||||
-rw-r--r-- | src/main.rs | 4 |
2 files changed, 15 insertions, 5 deletions
@@ -1,11 +1,22 @@ | |||
1 | use colored::*; | ||
1 | use std::env; | 2 | use std::env; |
2 | use tico::tico; | 3 | use tico::tico; |
3 | use colored::*; | ||
4 | 4 | ||
5 | pub fn cwd() -> Option<colored::ColoredString> { | 5 | pub fn cwd() -> Option<colored::ColoredString> { |
6 | let path_env = env::current_dir().ok()?; | 6 | let path_env = env::current_dir().ok()?; |
7 | let mut path = format!("{}", path_env.display()); | 7 | let mut path = format!("{}", path_env.display()); |
8 | let home = env::var("HOME").unwrap(); | 8 | let home = env::var("HOME").unwrap(); |
9 | |||
10 | let hide_home = env::var("HIDE_HOME_CWD").unwrap_or("0".into()); | ||
11 | match hide_home.as_ref() { | ||
12 | "0" => {} | ||
13 | _ => { | ||
14 | if &path == &home { | ||
15 | return Some(colored::ColoredString::from("")); | ||
16 | } | ||
17 | } | ||
18 | } | ||
19 | |||
9 | let tilde_expand = env::var("EXPAND_TILDE").unwrap_or("0".into()); | 20 | let tilde_expand = env::var("EXPAND_TILDE").unwrap_or("0".into()); |
10 | 21 | ||
11 | match tilde_expand.as_ref() { | 22 | match tilde_expand.as_ref() { |
@@ -23,7 +34,6 @@ pub fn cwd() -> Option<colored::ColoredString> { | |||
23 | let cwd_color = env::var("CWD_COLOR").unwrap_or("white".into()); | 34 | let cwd_color = env::var("CWD_COLOR").unwrap_or("white".into()); |
24 | match cwd_shorten.as_ref() { | 35 | match cwd_shorten.as_ref() { |
25 | "0" => return Some(path.color(cwd_color)), | 36 | "0" => return Some(path.color(cwd_color)), |
26 | _ => return Some(tico(&path).color(cwd_color)) | 37 | _ => return Some(tico(&path).color(cwd_color)), |
27 | } | 38 | } |
28 | |||
29 | } | 39 | } |
diff --git a/src/main.rs b/src/main.rs index 6ccca7b..aa19abd 100644 --- a/src/main.rs +++ b/src/main.rs | |||
@@ -40,7 +40,7 @@ fn pista(zsh: bool) -> String { | |||
40 | }; | 40 | }; |
41 | let (branch, status) = match env::var("DISABLE_VCS").unwrap_or("0".into()).as_ref() { | 41 | let (branch, status) = match env::var("DISABLE_VCS").unwrap_or("0".into()).as_ref() { |
42 | "0" => vcs::vcs_status().unwrap_or(("".into(), "".into())), | 42 | "0" => vcs::vcs_status().unwrap_or(("".into(), "".into())), |
43 | _ => ("".into(), "".into()) | 43 | _ => ("".into(), "".into()), |
44 | }; | 44 | }; |
45 | let venv = venv::get_name(); | 45 | let venv = venv::get_name(); |
46 | let prompt_char = prompt_char::get_char(); | 46 | let prompt_char = prompt_char::get_char(); |
@@ -75,7 +75,7 @@ fn pista_minimal(zsh: bool) -> String { | |||
75 | let mut vcs_component = String::new(); | 75 | let mut vcs_component = String::new(); |
76 | if let Some((branch, status)) = vcs_tuple { | 76 | if let Some((branch, status)) = vcs_tuple { |
77 | vcs_component = format!(" [{} {}] ", branch, status); | 77 | vcs_component = format!(" [{} {}] ", branch, status); |
78 | } else { | 78 | } else if cwd.len() > 0 { |
79 | vcs_component.push(' '); | 79 | vcs_component.push(' '); |
80 | } | 80 | } |
81 | let venv = venv::get_name(); | 81 | let venv = venv::get_name(); |