diff options
Diffstat (limited to 'src/files.rs')
-rw-r--r-- | src/files.rs | 70 |
1 files changed, 1 insertions, 69 deletions
diff --git a/src/files.rs b/src/files.rs index c240920..a3cd0ab 100644 --- a/src/files.rs +++ b/src/files.rs @@ -6,8 +6,6 @@ use std::path::{Path, PathBuf}; use std::sync::{Arc, Mutex, RwLock}; use std::sync::mpsc::Sender; use std::hash::{Hash, Hasher}; -use std::os::unix::ffi::{OsStringExt, OsStrExt}; -use std::ffi::{OsStr, OsString}; use lscolors::LsColors; use tree_magic; @@ -20,6 +18,7 @@ use failure::Error; use notify::DebouncedEvent; use rayon::{ThreadPool, ThreadPoolBuilder}; use alphanumeric_sort::compare_str; +use pathbuftools::PathBufTools; use crate::fail::{HResult, HError, ErrorLog}; use crate::dirty::{AsyncDirtyBit, DirtyBit, Dirtyable}; @@ -997,70 +996,3 @@ impl File { self.path.short_string() } } - - -pub trait PathBufExt { - fn short_path(&self) -> PathBuf; - fn short_string(&self) -> String; - fn name_starts_with(&self, pat: &str) -> bool; - fn quoted_file_name(&self) -> Option<OsString>; - fn quoted_path(&self) -> OsString; -} - -impl PathBufExt for PathBuf { - fn short_path(&self) -> PathBuf { - if let Ok(home) = crate::paths::home_path() { - if let Ok(short) = self.strip_prefix(home) { - let mut path = PathBuf::from("~"); - path.push(short); - return path - } - } - return self.clone(); - } - - fn short_string(&self) -> String { - self.short_path().to_string_lossy().to_string() - } - - fn name_starts_with(&self, pat: &str) -> bool { - if let Some(name) = self.file_name() { - let nbytes = name.as_bytes(); - let pbytes = pat.as_bytes(); - - if nbytes.starts_with(pbytes) { - return true; - } else { - return false; - } - } - false - } - - fn quoted_file_name(&self) -> Option<OsString> { - if let Some(name) = self.file_name() { - let mut name = name.as_bytes().to_vec(); - let mut quote = "\"".as_bytes().to_vec(); - let mut quoted = vec![]; - quoted.append(&mut quote.clone()); - quoted.append(&mut name); - quoted.append(&mut quote); - - let quoted_name = OsStr::from_bytes("ed).to_os_string(); - return Some(quoted_name); - } - None - } - - fn quoted_path(&self) -> OsString { - let mut path = self.clone().into_os_string().into_vec(); - let mut quote = "\"".as_bytes().to_vec(); - - let mut quoted = vec![]; - quoted.append(&mut quote.clone()); - quoted.append(&mut path); - quoted.append(&mut quote); - - OsString::from_vec(quoted) - } -} |