From e8eb685e58916b9c2e0942f6e7b68377e66ad831 Mon Sep 17 00:00:00 2001 From: Ajeet D'Souza <98ajeet@gmail.com> Date: Fri, 29 May 2020 03:47:24 +0530 Subject: [PATCH] Add _ZO_FZF_OPTS to specify `fzf` options --- src/config.rs | 5 +++++ src/fzf.rs | 14 ++++++++++---- src/subcommand/query.rs | 2 +- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/config.rs b/src/config.rs index 790498e..2d91116 100644 --- a/src/config.rs +++ b/src/config.rs @@ -4,6 +4,7 @@ use anyhow::{bail, Context, Result}; use std::env; use std::fs; +use std::ffi::OsString; use std::path::PathBuf; pub fn zo_data_dir() -> Result { @@ -33,6 +34,10 @@ pub fn zo_exclude_dirs() -> Vec { } } +pub fn zo_fzf_opts() -> Option { + env::var_os("_ZO_FZF_OPTS") +} + pub fn zo_maxage() -> Result { match env::var_os("_ZO_MAXAGE") { Some(maxage_osstr) => { diff --git a/src/fzf.rs b/src/fzf.rs index 96c01ec..2a74537 100644 --- a/src/fzf.rs +++ b/src/fzf.rs @@ -1,3 +1,4 @@ +use crate::config::zo_fzf_opts; use crate::db::{Dir, Epoch}; use crate::error::SilentExit; @@ -14,12 +15,17 @@ pub struct Fzf { impl Fzf { pub fn new() -> Result { - let child = Command::new("fzf") + let mut command = Command::new("fzf"); + command .args(&["-n2..", "--no-sort"]) .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .spawn() - .context("could not launch fzf")?; + .stdout(Stdio::piped()); + + if let Some(fzf_opts) = zo_fzf_opts() { + command.env("FZF_DEFAULT_OPTS", fzf_opts); + } + + let child = command.spawn().context("could not launch fzf")?; Ok(Fzf { child, diff --git a/src/subcommand/query.rs b/src/subcommand/query.rs index a4ad365..c51229b 100644 --- a/src/subcommand/query.rs +++ b/src/subcommand/query.rs @@ -94,7 +94,7 @@ fn query_interactive(keywords: &[String]) -> Result> { continue; } - fzf.write_dir(&dir, now); + fzf.write_dir(dir, now); } fzf.wait_selection()