Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/location.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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())
}
}

Expand Down