Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Option to direct cd bookmark in case of exact match #53

Open
erikw opened this issue Feb 15, 2022 · 4 comments
Open

Comments

@erikw
Copy link

erikw commented Feb 15, 2022

Hey,

first thank you for this cool plugin!

As I just started to use it I already noticed a part of my workflow from a previous shell plugin manager that did not translate well to fzf-marks for me. If I type $ fzm abc and there are many bookmarks who's bookmark name matches abc, it's completely reasonable to open up the FZF selector window (current behaviour).

However in the case it's already an exact match of a bookmark, that is I have a bookmark with name abc, I would expect that I directly cd to that bookmark instead of showing suggestions for other partial matches.

This is important to be able to work fast in the shell. If I know that I want to go to bookmark abc, then $ fzm abc should be enough to take me there. Currently the window will pop up on a exact name match and I need to press enter to go there.

As this is maybe not the behaviour that everyone desires, I would propose that we introduce a new opt-in configuration option:

Config Default Description
FZF_MARKS_JUMP_EXACT_MATCH false With fzm, cd to bookmark directly if the optional-initial-query is an exact match for a bookmark
@erikw erikw changed the title [Feature Request] Option to cd to bookmark in case of exact match [Feature Request] Option to direct cd bookmark in case of exact match Feb 15, 2022
@urbainvaes
Copy link
Owner

urbainvaes commented Feb 16, 2022

Hi,

Many thanks for the feedback. In my configuration I define

# You will need to change the first line
FZF_MARKS_PLUGIN_ZSH=$HOME/dotfiles/plugins/fzf-marks/fzf-marks.plugin.zsh
source "$FZF_MARKS_PLUGIN_ZSH"
FZF_MARKS_COMMAND="$FZF_MARKS_COMMAND -e -n 1'"

The option -e enables exact matching, and the option -1 enables auto-accept when there is only one match. Might this solve your issue?

@erikw
Copy link
Author

erikw commented Feb 16, 2022

Thank you for the suggestion.

Hmm

FZF_MARKS_COMMAND="$FZF_MARKS_COMMAND -e -n 1'"

is not valid because the single quote before the last double quote. I would assume that you mean

FZF_MARKS_COMMAND="$FZF_MARKS_COMMAND -e -n -1'"

I'm not sure what the the -nis supposed to do. From the fzf manual I see

-1, --select-1
                If there is only one match for the initial query (--query), do not start interactive finder and automatically select the only match
[...]
        -n, --nth=N[,..]
                Comma-separated list of field index expressions for limiting search scope.  See FIELD INDEX EXPRESSION for the details.
[...]
 FIELD INDEX EXPRESSION
         A field index expression can be a non-zero integer or a range expression ([BEGIN]..[END]). --nth and --with-nth take a comma-separated list of field index expressions.


     Examples
         1      The 1st field
         2      The 2nd field
         -1     The last field

When using this FZF_MARKS_COMMAND above,

  • Bookmarks are not found at all
  • They are actually being deleted from the marks file after failed lookup (!!). I needed to add my bookmarks back many times trying this out.
    • Turns out that I usually do ctrl+d to close/discard fzf selection. However in fzf-marks, ctrl+d means delete mark. Is there a way to change this to another key combination? :P It would be nice if fzf selection window consistently as usual.

However if I remove the -n to make it

FZF_MARKS_COMMAND="$FZF_MARKS_COMMAND -e -1'"

it works slightly better. With this, jump is done directly to exact match, but only if there are no other matches.

E.g. with marks abc, def, defg

$ fzm abc   # Jumps directly to destination of abc
$ fzm def   # shows fzf selection window with result def & defg. However is exact match and should jump to def destination directly!

Edit.

I figured that you maybe meant

FZF_MARKS_COMMAND="$FZF_MARKS_COMMAND -e -n 1 -1"

which with spelled out long-names is

FZF_MARKS_COMMAND="$FZF_MARKS_COMMAND --exact --nth=1 --select-1"

However the behavior is still the same that an initial query for an exact bookmark def still shows selection window for def & defg instead of going to def directly

@urbainvaes
Copy link
Owner

urbainvaes commented Feb 17, 2022

Hi,

Sorry, I responded a little bit too fast. It is indeed the -1 flag, which is enabled by default in the code of the plugin, that is responsible for the "auto-accept on exact match" behavior.

I also understand your issue better: you would like the plugin to auto-accept on exact match even if the initial query is an exact substring of one of the other marks. It's not unreasonable, and I'll take a look at this when I get the time.

Turns out that I usually do ctrl+d to close/discard fzf selection. However in fzf-marks, ctrl+d means delete mark. Is there a way to change this to another key combination? :P It would be nice if fzf selection window consistently as usual.

Yes, just set FZF_MARKS_DELETE to the key you want to use.

@erikw
Copy link
Author

erikw commented Feb 17, 2022

you would like the plugin to auto-accept on exact match even if the initial query is an exact substring of one of the other marks. It's not unreasonable, and I'll take a look at this when I get the time.

Exactly! :). As maybe not everyone would like this behavior, I think it could be an opt-in e.g. FZF_MARKS_JUMP_EXACT_MATCH=true

Yes, just set FZF_MARKS_DELETE to the key you want to use.

Just perfect. Now I can continue using ctrl+d consistently in all fzf-plugins. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants