Allow set the path to history and init file with env variables: LESSKEY_HISTORY and LESSKEY_INIT.

This commit is contained in:
Oleksandr Kozachuk
2022-12-17 20:05:57 +01:00
parent 982e3c3de3
commit 5ef5ef20ec
3 changed files with 16 additions and 6 deletions
+2 -2
View File
@@ -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,
+1 -1
View File
@@ -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(_) => (),
+13 -3
View File
@@ -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<Path> = {
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<Path> = {
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)]