diff --git a/Cargo.lock b/Cargo.lock index 3181aa5..086474d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1115,7 +1115,7 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "xplr" -version = "0.13.7" +version = "0.14.0" dependencies = [ "ansi-to-tui", "anyhow", diff --git a/Cargo.toml b/Cargo.toml index 427ffa4..f20625e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "xplr" -version = "0.13.7" # Update lua.rs +version = "0.14.0" # Update lua.rs authors = ["Arijit Basu "] edition = "2018" description = "A hackable, minimal, fast TUI file explorer" diff --git a/benches/criterion.rs b/benches/criterion.rs index 9ad5b73..fb49f9d 100644 --- a/benches/criterion.rs +++ b/benches/criterion.rs @@ -18,7 +18,7 @@ fn navigation_benchmark(c: &mut Criterion) { }); let lua = mlua::Lua::new(); - let mut app = app::App::create(PWD.into(), &lua).expect("failed to create app"); + let mut app = app::App::create(PWD.into(), &lua, None).expect("failed to create app"); app = app .clone() @@ -96,7 +96,7 @@ fn draw_benchmark(c: &mut Criterion) { }); let lua = mlua::Lua::new(); - let mut app = app::App::create(PWD.into(), &lua).expect("failed to create app"); + let mut app = app::App::create(PWD.into(), &lua, None).expect("failed to create app"); app = app .clone() diff --git a/src/app.rs b/src/app.rs index 7211183..34453ef 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1521,17 +1521,19 @@ pub struct App { } impl App { - pub fn create(pwd: PathBuf, lua: &mlua::Lua) -> Result { + pub fn create(pwd: PathBuf, lua: &mlua::Lua, config_file: Option) -> Result { let config = lua::init(lua)?; - let config_dir = dirs::config_dir() - .unwrap_or_else(|| PathBuf::from(".")) - .join("xplr"); - - let lua_script_file = config_dir.join("init.lua"); + let config_file = if let Some(path) = config_file { + path + } else if let Some(dir) = dirs::home_dir() { + dir.join(".config").join("xplr").join("init.lua") + } else { + PathBuf::from("/").join("etc").join("xplr").join("init.lua") + }; - let (config, load_err) = if lua_script_file.exists() { - match lua::extend(lua, &lua_script_file.to_string_lossy().to_string()) { + let (config, load_err) = if config_file.exists() { + match lua::extend(lua, &config_file.to_string_lossy().to_string()) { Ok(c) => (c, None), Err(e) => (config, Some(e.to_string())), } diff --git a/src/bin/xplr.rs b/src/bin/xplr.rs index 78ed84d..e226f59 100644 --- a/src/bin/xplr.rs +++ b/src/bin/xplr.rs @@ -11,7 +11,8 @@ use xplr::app; struct Cli { version: bool, help: bool, - path: Option, + path: Option, + config: Option, on_load: Vec, } @@ -41,12 +42,14 @@ impl Cli { "--" => { if cli.path.is_none() { - cli.path = args.pop_front(); + cli.path = args.pop_front().map(PathBuf::from); } return Ok(cli); } // Options + "-c" | "--config" => cli.config = args.pop_front().map(PathBuf::from), + "--on-load" => { while let Some(msg) = args.pop_front() { if msg.starts_with('-') { @@ -81,13 +84,15 @@ fn main() { xplr [FLAG]... [OPTION]... [PATH]"###; let flags = r###" - - Read PATH from stdin + - Read path from stdin -- End of flags and options -h, --help Prints help information -V, --version Prints version information"###; let options = r###" - --on-load ... Send messages when xplr loads"###; + -c, --config Specifies a custom config file (default is + "$HOME/.config/xplr/init.lua") + --on-load ... Sends messages when xplr loads"###; let args = r###" Path to focus on, or enter if directory"###; @@ -108,8 +113,9 @@ fn main() { } else if cli.version { println!("xplr {}", xplr::app::VERSION); } else { - match app::runner(cli.path.as_ref().map(PathBuf::from)) - .map(|a| a.with_on_load(cli.on_load)) + match app::runner(cli.path.clone()) + .map(|a| a.with_on_load(cli.on_load.clone())) + .map(|a| a.with_config(cli.config)) .and_then(|a| a.run()) { Ok(Some(out)) => print!("{}", out), diff --git a/src/lua.rs b/src/lua.rs index ba0e07d..49c4838 100644 --- a/src/lua.rs +++ b/src/lua.rs @@ -131,18 +131,24 @@ mod test { #[test] fn test_compatibility() { assert!(check_version(VERSION, "foo path").is_ok()); - assert!(check_version("0.13.0", "foo path").is_ok()); - assert!(check_version("0.13.1", "foo path").is_ok()); - assert!(check_version("0.13.2", "foo path").is_ok()); - assert!(check_version("0.13.3", "foo path").is_ok()); - assert!(check_version("0.13.4", "foo path").is_ok()); - assert!(check_version("0.13.5", "foo path").is_ok()); - assert!(check_version("0.13.6", "foo path").is_ok()); - assert!(check_version("0.13.7", "foo path").is_ok()); - - assert!(check_version("0.13.8", "foo path").is_err()); - assert!(check_version("0.14.7", "foo path").is_err()); - assert!(check_version("0.11.7", "foo path").is_err()); - assert!(check_version("1.13.7", "foo path").is_err()); + + // Current release if OK + assert!(check_version("0.14.0", "foo path").is_ok()); + + // Prev major release is ERR + + // Prev minor release is ERR (Change when we get to v1) + assert!(check_version("0.13.0", "foo path").is_err()); + + // Prev bugfix release is OK + + // Next major release is ERR + assert!(check_version("1.14.0", "foo path").is_err()); + + // Next minor release is ERR + assert!(check_version("0.15.0", "foo path").is_err()); + + // Next bugfix release is ERR (Change when we get to v1) + assert!(check_version("0.14.1", "foo path").is_err()); } } diff --git a/src/runner.rs b/src/runner.rs index 8a8c02e..2166a1d 100644 --- a/src/runner.rs +++ b/src/runner.rs @@ -90,6 +90,7 @@ fn call(app: &app::App, cmd: app::Command, silent: bool) -> io::Result, + config: Option, on_load: Vec, } @@ -106,6 +107,7 @@ impl Runner { Ok(Self { pwd, focused_path, + config: None, on_load: Default::default(), }) } @@ -115,9 +117,14 @@ impl Runner { self } + pub fn with_config(mut self, config: Option) -> Self { + self.config = config; + self + } + pub fn run(self) -> Result> { let lua = mlua::Lua::new(); - let mut app = app::App::create(self.pwd, &lua)?; + let mut app = app::App::create(self.pwd, &lua, self.config)?; fs::create_dir_all(app.session_path())?;