diff options
author | rabite <rabite@posteo.de> | 2019-03-17 01:50:38 +0100 |
---|---|---|
committer | rabite <rabite@posteo.de> | 2019-03-17 01:50:38 +0100 |
commit | 7011023babde960b8ce7a4fbbdddaab696c44649 (patch) | |
tree | cf6ca645b201eb319d10a99731bfe57cc2733e21 /src/files.rs | |
parent | 8b1c4db9cfa2ea0bf02e9e96c29b2510bbc391af (diff) |
shorten home path for display
Diffstat (limited to 'src/files.rs')
-rw-r--r-- | src/files.rs | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/files.rs b/src/files.rs index 5cc7dd8..49741df 100644 --- a/src/files.rs +++ b/src/files.rs @@ -602,4 +602,15 @@ impl File { = chrono::Local.timestamp(self.meta().unwrap().mtime(), 0); Some(time.format("%F %R").to_string()) } + + pub fn short_path(&self) -> HResult<PathBuf> { + if let Ok(home) = crate::paths::home_path() { + if let Ok(short) = self.path.strip_prefix(home) { + let mut path = PathBuf::from("~"); + path.push(short); + return Ok(path); + } + } + return Ok(self.path.clone()) + } } |