junegunn / fzf

:cherry_blossom: A command-line fuzzy finder
https://junegunn.github.io/fzf/
MIT License
62.31k stars 2.35k forks source link

Is it possible to create new bind on action from transform #3783

Closed schabrolles closed 2 months ago

schabrolles commented 2 months ago

Checklist

Output of fzf --version

0.51.0

OS

Shell

Problem / Steps to reproduce

I'm looking for a way to toggle an auto-refresh (watch mode) of the main view when I press ctrl-w.

For the moment, I can achieve this but the watch mode must be activate with a --bind option and I can only deactivate/reactivate it by pressing ctrl-w. I would like to start with this "auto-refresh" disabled by default.

My understanding is we can only "unbind" or "rebind" an action that has been already defined from the start.

snip from what I use (FZF_DEFAULT_COMMAND is a kind of "kubectl get pod")

fzf --prompt "(watch) $TYPE > " \
--bind="load:reload-sync%\$(echo \$FZF_DEFAULT_COMMAND); sleep 2%" \
--bind="ctrl-w:transform:[[ ! \$FZF_PROMPT =~ (watch) ]] && echo \"change-prompt((watch) $TYPE > )+rebind(load)+reload%\$(echo \$FZF_DEFAULT_COMMAND)%\" || echo \"change-prompt($TYPE > )+unbind(load)\"" \

I don't know if it is possible to have an option to create new bind with transform.

junegunn commented 2 months ago

My understanding is we can only "unbind" or "rebind" an action that has been already defined from the start.

Correct.

I would like to start with this "auto-refresh" disabled by default.

You can unbind the load on start like so:

date |
  fzf --prompt 'hold> ' \
      --bind 'start:unbind(load)' \
      --bind 'load:reload-sync:sleep 1; date' \
      --bind 'space:transform:
        [[ $FZF_PROMPT =~ watch ]] &&
          echo "change-prompt(hold> )+unbind(load)" ||
          echo "change-prompt(watch> )+rebind(load)+reload-sync(date)"
      '
schabrolles commented 2 months ago

Many thanks 🙏 fzf is a really cool, flexible. great work.