Add _ZO_FZF_OPTS to specify fzf options

This commit is contained in:
Ajeet D'Souza 2020-05-29 03:47:24 +05:30
parent d8a29f4367
commit e8eb685e58
3 changed files with 16 additions and 5 deletions

View File

@ -4,6 +4,7 @@ use anyhow::{bail, Context, Result};
use std::env; use std::env;
use std::fs; use std::fs;
use std::ffi::OsString;
use std::path::PathBuf; use std::path::PathBuf;
pub fn zo_data_dir() -> Result<PathBuf> { pub fn zo_data_dir() -> Result<PathBuf> {
@ -33,6 +34,10 @@ pub fn zo_exclude_dirs() -> Vec<PathBuf> {
} }
} }
pub fn zo_fzf_opts() -> Option<OsString> {
env::var_os("_ZO_FZF_OPTS")
}
pub fn zo_maxage() -> Result<Rank> { pub fn zo_maxage() -> Result<Rank> {
match env::var_os("_ZO_MAXAGE") { match env::var_os("_ZO_MAXAGE") {
Some(maxage_osstr) => { Some(maxage_osstr) => {

View File

@ -1,3 +1,4 @@
use crate::config::zo_fzf_opts;
use crate::db::{Dir, Epoch}; use crate::db::{Dir, Epoch};
use crate::error::SilentExit; use crate::error::SilentExit;
@ -14,12 +15,17 @@ pub struct Fzf {
impl Fzf { impl Fzf {
pub fn new() -> Result<Self> { pub fn new() -> Result<Self> {
let child = Command::new("fzf") let mut command = Command::new("fzf");
command
.args(&["-n2..", "--no-sort"]) .args(&["-n2..", "--no-sort"])
.stdin(Stdio::piped()) .stdin(Stdio::piped())
.stdout(Stdio::piped()) .stdout(Stdio::piped());
.spawn()
.context("could not launch fzf")?; 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 { Ok(Fzf {
child, child,

View File

@ -94,7 +94,7 @@ fn query_interactive(keywords: &[String]) -> Result<Option<String>> {
continue; continue;
} }
fzf.write_dir(&dir, now); fzf.write_dir(dir, now);
} }
fzf.wait_selection() fzf.wait_selection()