Address PR feedback
This commit is contained in:
parent
6b68d587fa
commit
827c099b68
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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<PathBuf> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn zo_fzf_args() -> Result<Vec<String>> {
|
||||
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<Rank> {
|
||||
match env::var_os("_ZO_MAXAGE") {
|
||||
Some(maxage_osstr) => match maxage_osstr.to_str() {
|
||||
|
|
@ -52,19 +59,3 @@ pub fn zo_maxage() -> Result<Rank> {
|
|||
None => Ok(1000.0),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn zo_fzf_extra_args() -> Result<Vec<String>> {
|
||||
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![]),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,9 +74,11 @@ pub fn fzf_helper<'a, I>(now: Epoch, dirs: I) -> Result<Option<Vec<u8>>>
|
|||
where
|
||||
I: IntoIterator<Item = &'a Dir>,
|
||||
{
|
||||
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()
|
||||
|
|
|
|||
Loading…
Reference in New Issue