From e426ee675844c90bea285b4bc8ec9a2cc5c3b4ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Gro=C3=9Fe?= Date: Sat, 27 Nov 2021 19:20:54 +0000 Subject: add HIDE_HOME_CWD config 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. --- readme.md | 3 +++ src/cwd.rs | 16 +++++++++++++--- src/main.rs | 4 ++-- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/readme.md b/readme.md index 2524932..c0629cd 100644 --- a/readme.md +++ b/readme.md @@ -94,6 +94,9 @@ export CWD_COLOR="white" # if EXPAND_TILDE is set to 0, `/home/nerdypepper` is shortened to `~` export EXPAND_TILDE=0 +# if HIDE_HOME_CWD is set to 1, path is hidden when in $HOME +export HIDE_HOME_CWD=1 + # there are three possible states for a git repo # - unstaged (working tree has been modified) # - staged (staging area has been modified) diff --git a/src/cwd.rs b/src/cwd.rs index c8af68e..3cc4a22 100644 --- a/src/cwd.rs +++ b/src/cwd.rs @@ -1,11 +1,22 @@ +use colored::*; use std::env; use tico::tico; -use colored::*; 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 hide_home = env::var("HIDE_HOME_CWD").unwrap_or("0".into()); + match hide_home.as_ref() { + "0" => {} + _ => { + if &path == &home { + return Some(colored::ColoredString::from("")); + } + } + } + let tilde_expand = env::var("EXPAND_TILDE").unwrap_or("0".into()); match tilde_expand.as_ref() { @@ -23,7 +34,6 @@ 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)), } - } 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 { }; let (branch, status) = match env::var("DISABLE_VCS").unwrap_or("0".into()).as_ref() { "0" => vcs::vcs_status().unwrap_or(("".into(), "".into())), - _ => ("".into(), "".into()) + _ => ("".into(), "".into()), }; let venv = venv::get_name(); let prompt_char = prompt_char::get_char(); @@ -75,7 +75,7 @@ fn pista_minimal(zsh: bool) -> String { let mut vcs_component = String::new(); if let Some((branch, status)) = vcs_tuple { vcs_component = format!(" [{} {}] ", branch, status); - } else { + } else if cwd.len() > 0 { vcs_component.push(' '); } let venv = venv::get_name(); -- cgit v1.2.3