diff --git a/README.md b/README.md index 3d5e666..a218267 100644 --- a/README.md +++ b/README.md @@ -128,8 +128,8 @@ NOTE: PWD hooks are currently not supported for POSIX shells. - `$_ZO_EXCLUDE_DIRS`: list of directories separated by platform-specific characters ("`:`" on Linux and macOS, and "`;`" on Windows) to be excluded from the database +- `$_ZO_FZF_ARGS`: extra arguments to pass to fzf, e.g. `--height 25` - `$_ZO_MAXAGE`: sets the maximum total rank after which entries start getting deleted -- `$_ZO_FZF_EXTRA_ARGS`: extra arguments to pass to fzf, e.g. `--height 25` [`dirs` documentation]: https://docs.rs/dirs/latest/dirs/fn.data_local_dir.html diff --git a/src/config.rs b/src/config.rs index 55988bd..733fec8 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,8 +1,7 @@ use crate::db::DBVersion; use crate::dir::Rank; -use anyhow::{bail, Context, Result}; -use shlex; +use anyhow::{anyhow, bail, Context, Result}; use std::env; use std::fs; @@ -37,6 +36,14 @@ pub fn zo_exclude_dirs() -> Vec { } } +pub fn zo_fzf_args() -> Result> { + match env::var("_ZO_FZF_ARGS") { + Ok(fzf_args) => shlex::split(&fzf_args).ok_or_else(|| anyhow!("could not parse _ZO_FZF_ARGS")), + Err(env::VarError::NotPresent) => Ok(Vec::new()), + Err(e) => Err(e).context("invalid Unicode in _ZO_FZF_ARGS"), + } +} + pub fn zo_maxage() -> Result { match env::var_os("_ZO_MAXAGE") { Some(maxage_osstr) => match maxage_osstr.to_str() { @@ -52,19 +59,3 @@ pub fn zo_maxage() -> Result { None => Ok(1000.0), } } - -pub fn zo_fzf_extra_args() -> Result> { - match env::var_os("_ZO_FZF_EXTRA_ARGS") { - Some(fzf_args_osstr) => match fzf_args_osstr.to_str() { - Some(fzf_args) => { - if let Some(args) = shlex::split(fzf_args) { - Ok(args) - } else { - bail!("Error parsing _ZO_FZF_EXTRA_ARGS"); - } - } - None => bail!("invalid Unicode in _ZO_FZF_EXTRA_ARGS"), - }, - None => Ok(vec![]), - } -} diff --git a/src/util.rs b/src/util.rs index 77fd2f7..280d795 100644 --- a/src/util.rs +++ b/src/util.rs @@ -74,9 +74,11 @@ pub fn fzf_helper<'a, I>(now: Epoch, dirs: I) -> Result>> where I: IntoIterator, { + let fzf_args = config::zo_fzf_args()?; + let mut fzf = Command::new("fzf") .args(&["-n2..", "--no-sort"]) - .args(config::zo_fzf_extra_args()?) + .args(fzf_args) .stdin(Stdio::piped()) .stdout(Stdio::piped()) .spawn()