junegunn / fzf

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

[Proposal] "Cursor Hold" expect to trigger after some time without keypresses #1211

Open thalesmello opened 6 years ago

thalesmello commented 6 years ago

I've included a comment a few days ago in #974 , but since that issue is closed, most likely it hadn't got any attention. Since it's a new proposal, I think it fits its own issue.

@junegunn Have you considered the possibility of binding a timeout after a certain length of time is passed without any keypresses, kind of like how CursorHold works in Vim?

Suppose something like:

fzf --expect=cursorhold --cursor-hold-timeout=500ms --require-input-before-cursor-hold ...

With all of that, it would be possible to implement similar behavior to how interactive selectors work, while keeping fzf a simple filter tool.

Besides, it could also have other uses, such as allowing scripts with timeout "default" options to be built. Kind of like how multi-boot systems work. A screen that allows the user to interact and choose a option, but it he doesn't do anything, it will just pick the default option (note that, for this to work, the --require-input-before-cursor-hold wouldn't be used).

jbriales commented 5 years ago

Any progress on this cursorhold feature?

zdykstra commented 5 years ago

I'd love to see this feature as well. I actually use fzf in a boot menu for ZFS, and I sorely missed this feature!

zfsbootmenu default timeout

Tholleman commented 1 year ago

Still hoping for this feature. Just changed one of my own scripts to use fzf instead of simply using read. Works perfectly fine except I used to be able to pass -t 60 to timeout after 60 seconds

LangLangBart commented 6 months ago

Possible workaround: Event that is triggered after x seconds of idle time.

Example: Provided that the user has selected at least one item and more than 2 seconds have elapsed since the line was focused, all selected items will be printed to the terminal.

look foo | fzf \
  --listen \
  --multi \
  --preview-window 0 \
  --preview $'
    while kill -0 "$PPID"; do
      if ((FZF_SELECT_COUNT && SECONDS > 2)); then
        curl "localhost:$FZF_PORT" --data "become:cat {+f}"
      else
        sleep 0.05
      fi
    done'
term description
--listen[^1] Allows sending commands to fzf.
--preview-window 0 With 0, the window is not visible, but the command is still executed.
kill -0 "$PPID" Checks if the parent process, in this case fzf, is still alive; true would work as well.
FZF_SELECT_COUNT[^2] An exported environment variable from fzf indicating the number of selected items.
SECONDS A parameter set by the shell (zsh, bash), indicating the number of seconds since shell invocation.
curl ... Sends an update to fzf.
FZF_PORT[^3] An exported environment variable from fzf for the port.
become:cat {+f} An fzf action to print all selected items to the terminal.
{+f} fzf placeholder for all selected lines (+) stored in a temporary file (f)

Fancy with 5s timer:

look foo | fzf \
  --listen \
  --multi \
  --preview-window 0 \
  --prompt "hello world ⧗ >" \
  --preview $'
    TMAX=5
    while kill -0 "$PPID"; do
      if ((FZF_SELECT_COUNT && SECONDS > TMAX)); then
        curl "localhost:$FZF_PORT" -d "become:cat {+f}"
      elif ((FZF_SELECT_COUNT)); then
        curl "localhost:$FZF_PORT" -d "change-prompt:${FZF_PROMPT%⧗*}⧗ $((TMAX - SECONDS))s > "
      else
        curl "localhost:$FZF_PORT" -d "change-prompt:${FZF_PROMPT%⧗*}⧗ > "
        sleep 0.2
      fi
    done'

[^1]: 0.36.0 CHANGELOG.md [^2]: 0.46.0 CHANGELOG.md [^3]: 0.39.0 CHANGELOG.md