Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: support fzf extra options#1026

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
ValJed wants to merge5 commits intoajeetdsouza:main
base:main
Choose a base branch
Loading
fromValJed:feature/fzf-extra-opts

Conversation

@ValJed
Copy link

@ValJedValJed commentedMar 24, 2025
edited
Loading

Description

Add support for a new env variable_ZO_FZF_EXTRA_OPTS to allow adding flags to the default ones, instead of erasing them.

This has been asked inthis issue.

Usage

Simply set_ZO_FZF_EXTRA_OPTS instead of_ZO_FZF_OPTS to append flags to the default ones.

stablestud, L3v3L, jack-mil, and ElgebarOri reacted with thumbs up emojinet, stablestud, and ElgebarOri reacted with hooray emojinet, stablestud, azaleacolburn, jack-mil, and ElgebarOri reacted with heart emoji
])
.enable_preview()
let default_args = config::fzf_default_args();
let args =ifletSome(fzf_extra_opts) = config::fzf_extra_opts(){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Since this returns values for both branches, it should probably be amatch expression.if let expressions are generally used when there's some code that ought to be conditionally executed, rather than being assigned to a variable in the parent scope.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Indeed, udpated too!

fnget_fzf() ->Result<FzfChild>{
letmut fzf =Fzf::new()?;
ifletSome(fzf_opts) = config::fzf_opts(){
ifletSome(mut fzf_opts) = config::fzf_opts(){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This could be a match expression

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

That's right, updated.

letmut fzf =Fzf::new()?;
ifletSome(fzf_opts) = config::fzf_opts(){
ifletSome(mut fzf_opts) = config::fzf_opts(){
ifletSome(fzf_extra_opts) = config::fzf_extra_opts(){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This is the right way to use anif let, since there's no other execution path.

ValJed reacted with thumbs up emoji
@azaleacolburn
Copy link
Contributor

diff --git a/src/cmd/query.rs b/src/cmd/query.rsindex adaeff7..652e624 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,33 @@ impl Query {      fn get_fzf() -> Result<FzfChild> {         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<String> = 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<String> = 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()     }

@ValJed
Copy link
Author

Thanks for the review@azaleacolburn.
I updated the code following your suggestions.

@ValJed
Copy link
Author

@ajeetdsouza Would love to see this merged 🙏🏼
Thanks in advance!

@azaleacolburn
Copy link
Contributor

@ajeetdsouza Several issues would be resolved by this feature, which you've already endorsed. I would love to get your review on this PR.

@j8s0n
Copy link

Will this feature make it into zoxide? When I runz foo and it goes to the wrong directory, I have to run a second commandzi foo and select the other one. I don't want to runzi foo every time, because most of the time there's only one target.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@azaleacolburnazaleacolburnAwaiting requested review from azaleacolburn

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@ValJed@azaleacolburn@j8s0n

[8]ページ先頭

©2009-2025 Movatter.jp