diff --git a/src/main.rs b/src/main.rs index c1e03b3..7270014 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,7 +21,7 @@ use crate::structs::{Command, LKErr, INIT_FILE}; pub fn main() { let lk = Rc::new(RefCell::new(LK::new())); - match std::fs::read_to_string(INIT_FILE.as_path().to_str().unwrap()) { + match std::fs::read_to_string(INIT_FILE.to_str().unwrap()) { Ok(script) => match command_parser::script(&script) { Ok(cmd_list) => { for cmd in cmd_list { @@ -36,7 +36,7 @@ pub fn main() { Err(err) => { LKEval::new( Command::Error(LKErr::Error( - format!("Failed to read init file {:?}: {}", INIT_FILE.as_path(), err).as_str(), + format!("Failed to read init file {:?}: {}", INIT_FILE.to_str(), err).as_str(), )), lk.clone(), prompt_password, diff --git a/src/repl.rs b/src/repl.rs index cea7946..27f3d0a 100644 --- a/src/repl.rs +++ b/src/repl.rs @@ -45,7 +45,7 @@ impl LKRead { } pub fn read(&mut self) -> LKEval { - let history_file = HISTORY_FILE.as_path().to_str().unwrap(); + let history_file = HISTORY_FILE.to_str().unwrap(); self.rl.clear_history(); match self.rl.load_history(&history_file) { Ok(_) => (), diff --git a/src/structs.rs b/src/structs.rs index ab686c0..35e4416 100644 --- a/src/structs.rs +++ b/src/structs.rs @@ -1,11 +1,21 @@ use crate::password::{Comment, Name, PasswordRef}; use home::home_dir; use std::fmt; -use std::path::PathBuf; +use std::path::Path; lazy_static! { - pub static ref HISTORY_FILE: PathBuf = home_dir().unwrap().join(".lesskey_history"); - pub static ref INIT_FILE: PathBuf = home_dir().unwrap().join(".lesskeyrc"); + pub static ref HISTORY_FILE: Box = { + match std::env::var("LESSKEY_HISTORY") { + Ok(v) => Path::new(shellexpand::full(&v).unwrap().into_owned().as_str()).to_path_buf().into_boxed_path(), + _ => home_dir().unwrap().join(".lesskey_history").into_boxed_path(), + } + }; + pub static ref INIT_FILE: Box = { + match std::env::var("LESSKEY_INIT") { + Ok(v) => Path::new(shellexpand::full(&v).unwrap().into_owned().as_str()).to_path_buf().into_boxed_path(), + _ => home_dir().unwrap().join(".lesskeyrc").into_boxed_path(), + } + }; } #[derive(thiserror::Error, Debug, PartialEq)]