diff options
author | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2019-05-25 23:18:26 -0400 |
---|---|---|
committer | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2019-05-25 23:18:26 -0400 |
commit | a6da280c2989e96921b196d6b9a5de1c0d01f20e (patch) | |
tree | 662f0f1dbfd8af27f785a2b0e165e69733ec673a | |
parent | 27d3b33f44b68582d500f787e8f2fe5b68a4867d (diff) |
make home directory a global variable
-rw-r--r-- | src/commands/mod.rs | 9 | ||||
-rw-r--r-- | src/commands/tab_operations.rs | 12 | ||||
-rw-r--r-- | src/main.rs | 1 |
3 files changed, 12 insertions, 10 deletions
diff --git a/src/commands/mod.rs b/src/commands/mod.rs index cf3764f..0e1c190 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -45,6 +45,8 @@ use crate::context::JoshutoContext; use crate::error::{JoshutoError, KeymapError}; use crate::window::JoshutoView; +use crate::HOME_DIR; + #[derive(Debug)] pub enum CommandKeybind { SimpleKeybind(Box<JoshutoCommand>), @@ -76,8 +78,8 @@ pub struct ProgressInfo { pub fn from_args(command: &str, args: &str) -> Result<Box<JoshutoCommand>, KeymapError> { match command { "cd" => match args { - "" => match dirs::home_dir() { - Some(s) => Ok(Box::new(self::ChangeDirectory::new(s))), + "" => match HOME_DIR.as_ref() { + Some(s) => Ok(Box::new(self::ChangeDirectory::new(s.clone()))), None => Err(KeymapError::new( Some("cd"), String::from("Cannot find home directory"), @@ -87,6 +89,7 @@ pub fn from_args(command: &str, args: &str) -> Result<Box<JoshutoCommand>, Keyma args => match wordexp::wordexp(args, 0) { Ok(mut exp_strs) => match exp_strs.next() { Some(exp_str) => { + eprintln!("exp: {}", exp_str); Ok(Box::new(self::ChangeDirectory::new(PathBuf::from(exp_str)))) } None => Err(KeymapError::new( @@ -172,7 +175,7 @@ pub fn from_args(command: &str, args: &str) -> Result<Box<JoshutoCommand>, Keyma "prepend" => self::RenameFileMethod::Prepend, "overwrite" => self::RenameFileMethod::Overwrite, "append" => self::RenameFileMethod::Append, - _ => self::RenameFileMethod::Append, + _ => self::RenameFileMethod::Overwrite, }; Ok(Box::new(self::RenameFile::new(method))) } diff --git a/src/commands/tab_operations.rs b/src/commands/tab_operations.rs index b2bb6a8..c8106ba 100644 --- a/src/commands/tab_operations.rs +++ b/src/commands/tab_operations.rs @@ -6,6 +6,8 @@ use crate::error::JoshutoError; use crate::tab::JoshutoTab; use crate::window::JoshutoView; +use crate::HOME_DIR; + #[derive(Clone, Debug)] pub struct NewTab; @@ -18,13 +20,9 @@ impl NewTab { } pub fn new_tab(context: &mut JoshutoContext, view: &JoshutoView) -> Result<(), JoshutoError> { - let curr_path: path::PathBuf = match dirs::home_dir() { - Some(path) => path, - None => { - let err = - std::io::Error::new(std::io::ErrorKind::NotFound, "Cannot find home directory"); - return Err(JoshutoError::IO(err)); - } + let curr_path = match HOME_DIR.as_ref() { + Some(s) => s.clone(), + None => path::PathBuf::from("/"), }; match JoshutoTab::new(curr_path, &context.config_t.sort_option) { diff --git a/src/main.rs b/src/main.rs index e72dd0d..4c96326 100644 --- a/src/main.rs +++ b/src/main.rs @@ -46,6 +46,7 @@ lazy_static! { static ref THEME_T: JoshutoTheme = JoshutoTheme::get_config(); static ref MIMETYPE_T: JoshutoMimetype = JoshutoMimetype::get_config(); static ref PREVIEW_T: JoshutoPreview = JoshutoPreview::get_config(); + static ref HOME_DIR: Option<PathBuf> = dirs::home_dir(); } #[derive(StructOpt, Debug)] |