Skip to content

Commit

Permalink
Omit the directory and show the distance
Browse files Browse the repository at this point in the history
  • Loading branch information
Herbie34 committed Sep 26, 2024
1 parent 8e5ce77 commit 37fb766
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}

Expand Down

0 comments on commit 37fb766

Please sign in to comment.