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

Option -print-query does not print query string on Abort! #2075

Closed
4 of 10 tasks
antofthy opened this issue Jun 8, 2020 · 6 comments
Closed
4 of 10 tasks

Option -print-query does not print query string on Abort! #2075

antofthy opened this issue Jun 8, 2020 · 6 comments

Comments

@antofthy
Copy link

antofthy commented Jun 8, 2020

  • I have read through the manual page (man fzf)
  • I have the latest version of fzf
  • I have searched through the existing issues

Info

  • OS
    • Linux
    • Mac OS X
    • Windows
    • Etc.
  • Shell
    • bash
    • zsh
    • fish

Problem / Steps to reproduce

The -print-query generally output two lines, the final query string the user had typed (or updated), and the selection made.

However if the user decides none of the selections match by pressing ESC, then nothing is printed! In that case the current state of the query string (which the user had input) is lost!

In summery, either...
1/ If -print-query is given, always print the query, even on abort!
2/ OR a new option to only output the query string on ESC (abort)

I would still like to see the final query string printed in that case 'ESC' or (abort) action, so what the user has already typed can be used for further refinement, or as a 'user supplied result'. Right now that information is just lost (which can very VERY annoying).

As long as you can still get the final query string, you can use the exit status of fzf to decide how the output (selection or query string) is handled.

If -print-query always prints the query string, I could simply tail for the last line, which would be the the users selection, or the query string on ESC-abort. Though a different method may be needed for --multi

Example use... The user is selecting from a very long list of possibilities, but that list may not be complete, or contain what the user actually wants, (a list of known hosts for example). The query string by this time would have likely expanded to what the user actually wants, and did not find.

By returning the query string on an ESC (abort / Interupt selection) that string can be used continue to use the input they have already typed, without losing it.

@junegunn
Copy link
Owner

junegunn commented Jun 8, 2020

I see your point but I'd rather not change the current behavior because doing so will break backward compatibility. You can use --bind option to attach print-query action to escape key.

fzf --print-query --bind esc:print-query+abort

@junegunn junegunn closed this as completed Jun 8, 2020
@antofthy
Copy link
Author

antofthy commented Jun 9, 2020

Thanks... that worked perfectly.

Though I left out the --print-query and just used the bind for the specific situation.
(user makes a selection or aborts.

I am using it in a bash completion selection.
Now if the user types more in the query string, does not find what they want, they can abort,
and the updated query string replaces the the previous word they started the 'completion' with.
Perfect.

This should be in the manual :-) But then I suppose a lot of things should.

@antofthy
Copy link
Author

Actually it would be a nice addition for the ls ** completion!

That is ** gets replaced by the current query string (if not empty) is the user aborts.

@bhepple
Copy link

bhepple commented Mar 20, 2023

Thanks @antofthy for bringing this up and @junegunn for the fix - it was exactly what I am looking for!!

@spjspjspj
Copy link

ls ** completion

I just learned about this. Where can I find more info on commands like this? thanks!

@spjspjspj
Copy link

using it in a bash completion selection

I'm trying to apply this fix to a zsh history search. However, it's using a config like this and I don't know how to apply this fix here:

# Setup fzf
# ---------
if [[ ! "$PATH" == */opt/homebrew/opt/fzf/bin* ]]; then
  export PATH="${PATH:+${PATH}:}/opt/homebrew/opt/fzf/bin"
fi

# Auto-completion
# ---------------
[[ $- == *i* ]] && source "/opt/homebrew/opt/fzf/shell/completion.zsh" 2> /dev/null

# Key bindings
# ------------
source "/opt/homebrew/opt/fzf/shell/key-bindings.zsh"

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

4 participants