junegunn / fzf

:cherry_blossom: A command-line fuzzy finder

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is it possible to create new bind on action from transform

schabrolles opened this issue · comments

Checklist

  • I have read through the manual page (man fzf)
  • I have searched through the existing issues
  • For bug reports, I have checked if the bug is reproducible in the latest version of fzf

Output of fzf --version

0.51.0

OS

  • Linux
  • macOS
  • Windows
  • Etc.

Shell

  • bash
  • zsh
  • fish

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.

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)"
      '

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