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] dynamic replace-query #2465

Closed
6 of 10 tasks
githorse opened this issue Apr 24, 2021 · 4 comments
Closed
6 of 10 tasks

[FEATURE] dynamic replace-query #2465

githorse opened this issue Apr 24, 2021 · 4 comments

Comments

@githorse
Copy link

githorse commented Apr 24, 2021

  • 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

Idea

I'd like to create a "search engine" widget similar to Alfred/Albert or the Firefox/Chrome omnibar. To make this work, I want the user to be able to type in (customizable) triggers to perform different searches/actions:

ps:<space>    # trigger process search mode
files:<space> # trigger file search mode
dirs:<space>  # trigger directory search mode
etc.

I can achieve the functionality of this already by using change and reload to switch the logic based on the trigger sequence:

fzf --bind 'change:reload(custom-search {q})`

But I can't quite achieve the look that I want, because the trigger sequence of course is still displayed in the query.

image

Whereas what I really want is to either

  1. delete the trigger from the query string and absorb it into a dynamic prompt, or
  2. rewrite the query string itself, with ANSI colors.

Either of those options would allow me to mimic the omnibar search engine functionality to do something like this:

image

image

I'm guessing this would look something like:

fzf --bind 'change:replace-query(format_query {q})'

Note that we can get pretty close here with the --header-lines option. But presumably being able to rewrite the query at will would open up other nifty features (syntax highlighting?). There are some complications, like what to do with the cursor if you're not at the end of the line (maybe pass the cursor position as a second argument to format_query?)

See also my feature request for multi-character trigger sequences.

@jbriales
Copy link
Contributor

I second this. I was myself looking for a similar feature which would let me work around a nr of limitations I'm finding when using reload.
I saw replace-query in the actions and would have expected this could take an arbitrary parameter in as execute(...) or change-prompt(...) rather than being hardcoded to the current selection only.

E.g. in my case this would unblock me in #2456 because as a hacky workaround I would simply make sth like --bind 'space:reload(...)+replace_query({q} )' to add the space as wanted in the scenario mentioned there.

@SpicyLemon
Copy link

I would also like such a thing.

I basically want to be able to do my own search and set the query based on the results while still keeping all the options originally provided (i.e. I don't want to reload). This would filter the original input, but still allow for other things to be selected.

From what I can tell, the command isn't optional for any of the actions that take one in. So instead of overloading replace-query with replace-query(...), maybe it's better to have a separate action like change-query(...).

I'd basically use it like this: --bind 'ctrl+f:change-query(find_stuff {q})'.

@SpicyLemon
Copy link

I've created a PR for this: #2559

I'm not exactly sure how to go about contacting a maintainer to authorize workflows for me though.

@vovcacik
Copy link
Contributor

vovcacik commented Oct 5, 2021

This is not difficult to do.

fzf-prompt-demo

@echo off
setlocal

set "black=�[40m"
set "red=�[41m"
set "green=�[42m"
set "yellow=�[43m"
set "blue=�[44m"
set "magenta=�[45m"
set "cyan=�[46m"
set "white=�[47m"

set "reset=�[0m"

fzf.exe --bind "ctrl-p:change-prompt(%yellow%process: %reset%)+reload(tasklist)" --bind "ctrl-f:change-prompt(%blue%files: %reset%)+reload(ls -p | grep -v /)" --bind "ctrl-d:change-prompt(%magenta%dirs: %reset%)+reload(ls -p | grep / | grep {q})"

You need to replace the � with U+001B locally.

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

Successfully merging a pull request may close this issue.

4 participants