From 37fb76640a6de3192df0f7188a60c112a6be7c50 Mon Sep 17 00:00:00 2001 From: Herbie34 <1227499+Herbie34@users.noreply.github.com> Date: Thu, 26 Sep 2024 14:21:44 +0900 Subject: [PATCH 1/3] Omit the directory and show the distance --- src/location.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/location.rs b/src/location.rs index 0c0e7b27..3f97af1a 100644 --- a/src/location.rs +++ b/src/location.rs @@ -107,8 +107,20 @@ impl std::fmt::Display for Location { let mut loc = self.path.to_string_lossy().replace(&home, "~"); if loc == "~" { loc = "home".to_string(); + } else { + // 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("..."); + 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()) } } From d22ea4f1cbba36d68013423655b0276b6fd49cbc Mon Sep 17 00:00:00 2001 From: Herbie34 <1227499+Herbie34@users.noreply.github.com> Date: Fri, 11 Oct 2024 23:38:49 +0900 Subject: [PATCH 2/3] Add 2nd directory On Linux, components[0] is just '/', so it might be better to also add components[1]. --- src/location.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/location.rs b/src/location.rs index 3f97af1a..b31b56b0 100644 --- a/src/location.rs +++ b/src/location.rs @@ -115,6 +115,7 @@ impl std::fmt::Display for Location { 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(); From d0f5c97da282b9becd73f7bc7c894ac14bb3fbc6 Mon Sep 17 00:00:00 2001 From: Herbie34 <1227499+Herbie34@users.noreply.github.com> Date: Tue, 15 Oct 2024 23:53:45 +0900 Subject: [PATCH 3/3] Change the directory display according to the environment variable --- src/location.rs | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/location.rs b/src/location.rs index b31b56b0..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 { @@ -108,17 +109,19 @@ impl std::fmt::Display for Location { if loc == "~" { loc = "home".to_string(); } else { - // 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(); + 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, self.distance_from_home().len())