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

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

Open
thalesmello opened this issue Feb 7, 2018 · 4 comments
Labels

Comments

@thalesmello
Copy link

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 ...
  • --expect=cursorhold would be triggered after a certain length of time passed.
  • --cursor-hold-timeout=500ms would specify that amount of time
  • --require-input-before-cursor-hold would assert the timeout would only happen after some key was pressed

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
Copy link
Contributor

Any progress on this cursorhold feature?

@zdykstra
Copy link

zdykstra commented Nov 4, 2019

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
Copy link

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
Copy link
Contributor

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
--listen1 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_COUNT2 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_PORT3 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'

Footnotes

  1. 0.36.0 CHANGELOG.md

  2. 0.46.0 CHANGELOG.md

  3. 0.39.0 CHANGELOG.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants