fzf icon indicating copy to clipboard operation
fzf copied to clipboard

Reload with pre-selected items

Open sheluchin opened this issue 6 months ago • 4 comments

I am trying to create a binding that reloads the list and pre-selects items in the updated list. I looked at https://github.com/junegunn/fzf/issues/4396 and tried to do something like:

echo -e "1\n2\n3" | fzf --sync --multi --bind 'ctrl-a:reload-sync(echo -e 9\\n8)+pos(1)+select'

but the result is that the selection happens on the initial list, then the list gets updated with no selection.

I tried some other variations of my command but could not get it to work how I wanted.

sheluchin avatar Jun 03 '25 15:06 sheluchin

echo -e "1\n2\n3" | fzf --multi --bind ctrl-a:reload:'echo -e 9\\n8;touch /tmp/reloaded' --bind result:transform:'[[ -f /tmp/reloaded ]] && rm /tmp/reloaded && echo "pos(1)+select"'

nenahp avatar Jun 03 '25 16:06 nenahp

Thank you, @nenahp! That does indeed work. Is there a possible solution that doesn't depend on side effects like creating a temp file as a flag? I would like to chain many such actions together and this approach might not scale well.

sheluchin avatar Jun 04 '25 13:06 sheluchin

I don't know. Maybe you can use --listen. Then you can bind to a complex script. The script use curl localhost:$FZF_PORT to GET the state of fzf, or request some actions with POST.

nenahp avatar Jun 04 '25 14:06 nenahp

If your requirement is simple (e.g. selecting the first entry), you can bind actions to perform on load event.

fzf --multi --bind 'load:pos(1)+select' --bind 'space:reload(ls)+clear-query'

To avoid triggering the actions on load of the initial list,

fzf --multi --bind 'start:unbind(load),load:pos(1)+select' --bind 'space:rebind(load)+reload(ls)+clear-query'

junegunn avatar Jun 07 '25 17:06 junegunn