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] provide an easier version of "interactive command" mode (as skim does) #2843

Closed
5 of 10 tasks
Jiehong opened this issue Jun 7, 2022 · 1 comment
Closed
5 of 10 tasks
Labels

Comments

@Jiehong
Copy link

Jiehong commented Jun 7, 2022

  • 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

This is not a problem per say, but a feature request to make a common idea simpler.

Current state

Today, if you want to use fzf to interactively write shell commands, you can make use of the change and reload binding as explained in https://github.com/junegunn/fzf#3-interactive-ripgrep-integration:

INITIAL_QUERY=""
RG_PREFIX="rg --column --line-number --no-heading --color=always --smart-case "
FZF_DEFAULT_COMMAND="$RG_PREFIX '$INITIAL_QUERY'" \
  fzf --bind "change:reload:$RG_PREFIX {q} || true" \
      --ansi --disabled --query "$INITIAL_QUERY"

But that's quite a mouthful to write (and only works for bash, so it needs to be adapted by the user for another shell, such as fish or powershell for example).

However, this is something skim allows by providing a specific option for this right away:

sk --ansi --interactive --command 'rg --column --line-number --no-heading --color=always --smart-case "{}"'

And this will essentially do exactly the same thing (here {} takes the place of {q} from the fzf example).

Feature proposal

It would be pretty awesome if fzf could support the same thing, maybe as:

fzf --ansi --disabled --command --query 'rg --column --line-number --no-heading --color=always --smart-case "{q}"'

(and perhaps converting that case into the change:reload binding automatically for the user.

@junegunn
Copy link
Owner

junegunn commented Jun 8, 2022

Thanks for the suggestion, but I don't think we need to provide a shortcut.

However, this is something skim allows by providing a specific option for this right away:

Well, to be fair, the equivalent version for that is (not handling $INITIAL_QUERY) this, and I don't think it's too complicated.

RG="rg --column --line-number --no-heading --color=always --smart-case"
FZF_DEFAULT_COMMAND="$RG ''" fzf --bind "change:reload:$RG {q}" --ansi --disabled

While skim's approach may seem easier, it's not as flexible as the fzf's way. You can bind reload action to not just change event, but also to any key, and you can dynamically unbind and rebind it.

perhaps converting that case into the change:reload binding automatically for the user

You can easily do that with a shell script file; put a she-bang line and you can run it in any shell.

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

No branches or pull requests

2 participants