Add support for configurable extra fzf arguments

via the environment variable _ZO_FZF_EXTRA_ARGS
This commit is contained in:
Jason Shirk 2020-04-07 23:30:24 -07:00
parent aab37dfab9
commit 6b68d587fa
5 changed files with 27 additions and 0 deletions

7
Cargo.lock generated
View File

@ -311,6 +311,11 @@ dependencies = [
"syn 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "shlex"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "strsim"
version = "0.8.0"
@ -433,6 +438,7 @@ dependencies = [
"clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
"dirs 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.106 (registry+https://github.com/rust-lang/crates.io-index)",
"shlex 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"structopt 0.3.12 (registry+https://github.com/rust-lang/crates.io-index)",
"uuid 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -477,6 +483,7 @@ dependencies = [
"checksum rust-argon2 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2bc8af4bda8e1ff4932523b94d3dd20ee30a87232323eda55903ffd71d2fb017"
"checksum serde 1.0.106 (registry+https://github.com/rust-lang/crates.io-index)" = "36df6ac6412072f67cf767ebbde4133a5b2e88e76dc6187fa7104cd16f783399"
"checksum serde_derive 1.0.106 (registry+https://github.com/rust-lang/crates.io-index)" = "9e549e3abf4fb8621bd1609f11dfc9f5e50320802273b12f3811a67e6716ea6c"
"checksum shlex 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7fdf1b9db47230893d76faad238fd6097fd6d6a9245cd7a4d90dbd639536bbd2"
"checksum strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
"checksum structopt 0.3.12 (registry+https://github.com/rust-lang/crates.io-index)" = "c8faa2719539bbe9d77869bfb15d4ee769f99525e707931452c97b693b3f159d"
"checksum structopt-derive 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "3f88b8e18c69496aad6f9ddf4630dd7d585bcaf765786cb415b9aec2fe5a0430"

View File

@ -18,6 +18,7 @@ bincode = "1.2.1"
clap = "2.33.0"
dirs = "2.0.2"
serde = { version = "1.0.106", features = ["derive"] }
shlex = "0.1.1"
structopt = "0.3.12"
uuid = { version = "0.8.1", features = ["v4"] }

View File

@ -129,6 +129,7 @@ NOTE: PWD hooks are currently not supported for POSIX shells.
characters ("`:`" on Linux and macOS, and "`;`" on Windows) to be excluded from
the database
- `$_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

View File

@ -2,6 +2,7 @@ use crate::db::DBVersion;
use crate::dir::Rank;
use anyhow::{bail, Context, Result};
use shlex;
use std::env;
use std::fs;
@ -51,3 +52,19 @@ 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![]),
}
}

View File

@ -76,6 +76,7 @@ where
{
let mut fzf = Command::new("fzf")
.args(&["-n2..", "--no-sort"])
.args(config::zo_fzf_extra_args()?)
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.spawn()