diff --git a/src/location.rs b/src/location.rs index 0c0e7b27..1822c8a7 100644 --- a/src/location.rs +++ b/src/location.rs @@ -1,6 +1,7 @@ use crate::datafile::rpg_dir; use serde::{Deserialize, Serialize}; use std::path; +use std::env; #[derive(Serialize, Deserialize, Debug, Eq, Clone)] pub struct Location { @@ -107,8 +108,23 @@ impl std::fmt::Display for Location { let mut loc = self.path.to_string_lossy().replace(&home, "~"); if loc == "~" { loc = "home".to_string(); + } else { + if env::var("RPGCLI_OMITDIR").is_ok() { + // Omit the location + let path = path::PathBuf::from(loc.clone()); + let components: Vec<_> = path.components().collect(); + let len = components.len(); + if 3 < len { + let mut omitted_path = path::PathBuf::new(); + omitted_path.push(components[0]); + omitted_path.push(components[1]); + omitted_path.push("..."); + omitted_path.push(components[len - 1]); + loc = omitted_path.to_string_lossy().to_string(); + } + } } - write!(f, "{}", loc) + write!(f, "{}[{}]", loc, self.distance_from_home().len()) } }