From efac8588e90cffc18f6b774f3e3588be30a99fb4 Mon Sep 17 00:00:00 2001 From: Jed Date: Sat, 22 Mar 2025 17:21:10 +0100 Subject: [PATCH 1/5] gets new _ZO_FZF_EXTRA_OPTS and add it to the fzf flags when _ZO_FZF_OPTS exist --- src/cmd/query.rs | 7 ++++++- src/config.rs | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/cmd/query.rs b/src/cmd/query.rs index 362d80a37..cd5c4e733 100644 --- a/src/cmd/query.rs +++ b/src/cmd/query.rs @@ -91,7 +91,12 @@ impl Query { fn get_fzf() -> Result { let mut fzf = Fzf::new()?; - if let Some(fzf_opts) = config::fzf_opts() { + if let Some(mut fzf_opts) = config::fzf_opts() { + if let Some(fzf_extra_opts) = config::fzf_extra_opts() { + fzf_opts.push(" "); + fzf_opts.push(fzf_extra_opts); + } + fzf.env("FZF_DEFAULT_OPTS", fzf_opts) } else { fzf.args([ diff --git a/src/config.rs b/src/config.rs index 0aeda5c5c..e1a5c071d 100644 --- a/src/config.rs +++ b/src/config.rs @@ -47,6 +47,10 @@ pub fn fzf_opts() -> Option { env::var_os("_ZO_FZF_OPTS") } +pub fn fzf_extra_opts() -> Option { + env::var_os("_ZO_FZF_EXTRA_OPTS") +} + pub fn maxage() -> Result { env::var_os("_ZO_MAXAGE").map_or(Ok(10_000.0), |maxage| { let maxage = maxage.to_str().context("invalid unicode in _ZO_MAXAGE")?; From 0fac6195a623810141de0d62be0b08467b1f2ce5 Mon Sep 17 00:00:00 2001 From: Jed Date: Sun, 23 Mar 2025 18:44:24 +0100 Subject: [PATCH 2/5] gets _ZO_FZF_EXTRA_OPTS and add it to default fzf flags --- src/cmd/query.rs | 35 +++++++++++++++-------------------- src/config.rs | 22 ++++++++++++++++++++++ 2 files changed, 37 insertions(+), 20 deletions(-) diff --git a/src/cmd/query.rs b/src/cmd/query.rs index cd5c4e733..adaeff754 100644 --- a/src/cmd/query.rs +++ b/src/cmd/query.rs @@ -99,26 +99,21 @@ impl Query { fzf.env("FZF_DEFAULT_OPTS", fzf_opts) } else { - fzf.args([ - // Search mode - "--exact", - // Search result - "--no-sort", - // Interface - "--bind=ctrl-z:ignore,btab:up,tab:down", - "--cycle", - "--keep-right", - // Layout - "--border=sharp", // rounded edges don't display correctly on some terminals - "--height=45%", - "--info=inline", - "--layout=reverse", - // Display - "--tabstop=1", - // Scripting - "--exit-0", - ]) - .enable_preview() + let default_args = config::fzf_default_args(); + let args = if let Some(fzf_extra_opts) = config::fzf_extra_opts() { + let extra_fzf_args_list: Vec = fzf_extra_opts + .to_str() + .unwrap_or_default() + .split_whitespace() + .map(|arg| String::from(arg)) + .collect(); + + vec![default_args, extra_fzf_args_list].concat() + } else { + default_args + }; + + fzf.args(args).enable_preview() } .spawn() } diff --git a/src/config.rs b/src/config.rs index e1a5c071d..b2cf9861f 100644 --- a/src/config.rs +++ b/src/config.rs @@ -51,6 +51,28 @@ pub fn fzf_extra_opts() -> Option { env::var_os("_ZO_FZF_EXTRA_OPTS") } +pub fn fzf_default_args() -> Vec { + vec![ + // Search mode + String::from("--exact"), + // Search result + String::from("--no-sort"), + // Interface + String::from("--bind=ctrl-z:ignore,btab:up,tab:down"), + String::from("--cycle"), + String::from("--keep-right"), + // Layout + String::from("--border=sharp"), // rounded edges don't display correctly on some terminals + String::from("--height=45%"), + String::from("--info=inline"), + String::from("--layout=reverse"), + // Display + String::from("--tabstop=1"), + // Scripting + String::from("--exit-0"), + ] +} + pub fn maxage() -> Result { env::var_os("_ZO_MAXAGE").map_or(Ok(10_000.0), |maxage| { let maxage = maxage.to_str().context("invalid unicode in _ZO_MAXAGE")?; From 8360bd385c1e4d06739f4c5dc38439b10f58ea2a Mon Sep 17 00:00:00 2001 From: Jed Date: Mon, 24 Mar 2025 21:52:59 +0100 Subject: [PATCH 3/5] updates doc --- man/man1/zoxide.1 | 4 ++++ src/cmd/cmd.rs | 1 + 2 files changed, 5 insertions(+) diff --git a/man/man1/zoxide.1 b/man/man1/zoxide.1 index ef1792b66..2c765af30 100644 --- a/man/man1/zoxide.1 +++ b/man/man1/zoxide.1 @@ -92,6 +92,10 @@ to use \fBzoxide-remove\fR(1) to remove any existing entries from the database. Custom options to pass to \fBfzf\fR(1) during interactive selection. See the manpage for the full list of options. .TP +.B_ZO_FZF_EXTRA_OPTS +Custom options to pass to \fBfzf\fR(1) during interactive selection, appended to the default ones. +See the manpage for the full list of options. +.TP .B _ZO_MAXAGE Configures the aging algorithm, which limits the maximum number of entries in the database. By default, this is set to 10000. diff --git a/src/cmd/cmd.rs b/src/cmd/cmd.rs index cff7e790c..c5e6a82b4 100644 --- a/src/cmd/cmd.rs +++ b/src/cmd/cmd.rs @@ -26,6 +26,7 @@ https://github.com/ajeetdsouza/zoxide {tab}_ZO_ECHO {tab}Print the matched directory before navigating to it when set to 1 {tab}_ZO_EXCLUDE_DIRS {tab}List of directory globs to be excluded {tab}_ZO_FZF_OPTS {tab}Custom flags to pass to fzf +{tab}_ZO_FZF_EXTRA_OPTS {tab}Custom flags added the the default fzf ones {tab}_ZO_MAXAGE {tab}Maximum total age after which entries start getting deleted {tab}_ZO_RESOLVE_SYMLINKS{tab}Resolve symlinks when storing paths").into_resettable() } From 8fc4b2b58c6c0a64080a343e60425618f1ff7877 Mon Sep 17 00:00:00 2001 From: Jed Date: Mon, 19 May 2025 16:31:19 +0200 Subject: [PATCH 4/5] feedback: uses match instead of if else --- src/cmd/query.rs | 50 +++++++++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/src/cmd/query.rs b/src/cmd/query.rs index adaeff754..5b6d77459 100644 --- a/src/cmd/query.rs +++ b/src/cmd/query.rs @@ -3,7 +3,7 @@ use std::io::{self, Write}; use anyhow::{Context, Result}; use crate::cmd::{Query, Run}; -use crate::config; +use crate::config::{self}; use crate::db::{Database, Epoch, Stream, StreamOptions}; use crate::error::BrokenPipeHandler; use crate::util::{self, Fzf, FzfChild}; @@ -91,29 +91,35 @@ impl Query { fn get_fzf() -> Result { let mut fzf = Fzf::new()?; - if let Some(mut fzf_opts) = config::fzf_opts() { - if let Some(fzf_extra_opts) = config::fzf_extra_opts() { - fzf_opts.push(" "); - fzf_opts.push(fzf_extra_opts); + + match config::fzf_opts() { + Some(mut fzf_opts) => { + if let Some(fzf_extra_opts) = config::fzf_extra_opts() { + fzf_opts.push(" "); + fzf_opts.push(fzf_extra_opts); + } + + fzf.env("FZF_DEFAULT_OPTS", fzf_opts) } + None => { + let default_args = config::fzf_default_args(); + + let args = match config::fzf_extra_opts() { + Some(fzf_extra_opts) => { + let extra_fzf_args_list: Vec = fzf_extra_opts + .to_str() + .unwrap_or_default() + .split_whitespace() + .map(|arg| String::from(arg)) + .collect(); + + vec![default_args, extra_fzf_args_list].concat() + } + None => default_args, + }; - fzf.env("FZF_DEFAULT_OPTS", fzf_opts) - } else { - let default_args = config::fzf_default_args(); - let args = if let Some(fzf_extra_opts) = config::fzf_extra_opts() { - let extra_fzf_args_list: Vec = fzf_extra_opts - .to_str() - .unwrap_or_default() - .split_whitespace() - .map(|arg| String::from(arg)) - .collect(); - - vec![default_args, extra_fzf_args_list].concat() - } else { - default_args - }; - - fzf.args(args).enable_preview() + fzf.args(args).enable_preview() + } } .spawn() } From 7936aa6f4ca74ce2c3d0ffaf04899215d65cdd21 Mon Sep 17 00:00:00 2001 From: Jed Date: Fri, 23 May 2025 10:21:01 +0200 Subject: [PATCH 5/5] fixes lint checks --- src/cmd/query.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cmd/query.rs b/src/cmd/query.rs index 5b6d77459..24246b7a0 100644 --- a/src/cmd/query.rs +++ b/src/cmd/query.rs @@ -3,7 +3,7 @@ use std::io::{self, Write}; use anyhow::{Context, Result}; use crate::cmd::{Query, Run}; -use crate::config::{self}; +use crate::config; use crate::db::{Database, Epoch, Stream, StreamOptions}; use crate::error::BrokenPipeHandler; use crate::util::{self, Fzf, FzfChild};