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

Fzf should provide a way to dynamically rebind reload to change event after unbinding it #2752

Closed
5 of 10 tasks
Ultra-Code opened this issue Mar 9, 2022 · 3 comments
Closed
5 of 10 tasks
Assignees
Labels

Comments

@Ultra-Code
Copy link

Ultra-Code commented Mar 9, 2022

  • I have read through the manual page (man fzf)
  • I have the latest version of fzf
  • I have searched through the existing issues

Info

  • OS
    • Linux
    • Mac OS X
    • Windows
    • Etc.
  • Shell
    • bash
    • zsh
    • fish

Problem / Steps to reproduce

RG_PREFIX="rg --column --line-number --no-heading --color=always --smart-case "
INITIAL_QUERY="${*:-}"
IFS=: read -ra selected < <(
  FZF_DEFAULT_COMMAND="$RG_PREFIX $(printf %q "$INITIAL_QUERY")" \
  fzf --ansi \
      --color "hl:-1:underline,hl+:-1:underline:reverse" \
      --disabled --query "$INITIAL_QUERY" \
      --bind "change:reload:sleep 0.1; $RG_PREFIX {q} || true " \
      --bind "ctrl-f:unbind(change)+change-prompt(2. fzf> )+enable-search+clear-query" \
      --bind "ctrl-r:unbind(ctrl-f)+change-prompt(1. ripgrep> )+disable-search+clear-query,change:reload(sleep 0.1; $RG_PREFIX {q} || true)" \
      --prompt '1. ripgrep> ' \
      --delimiter : \
      --preview 'bat --color=always {1} --highlight-line {2}' \
      --preview-window 'up,60%,border-bottom,+{2}+3/3,~3'
)
[ -n "${selected[0]}" ] && $EDITOR "${selected[0]}" "+${selected[1]}"

I have been trying to dynamically reload entries from $RG_PREFIX with the ctrl-r keybinding but to no avail after unbinding the change event from reloading with the ctrl+f binding

I can manually reload $RG_PREFIX by chaining it to the ctrl-r keybinding .ie ctrl-r:unbind(ctrl-f)+change-prompt(1. ripgrep> )+disable-search+reload(sleep 0.1; $RG_PREFIX {q} || true) but that means i will have to click ctrl-r every time the query string changes which isn't idle ,flexible or efficient like have the change event automatically do the reload for me when the query string changes

So I request that fzf provides a way to do this , I believe this is a limitation that can be overcomed.
I am by no means a guru with Go but I'm welling to learn and help anyone who will be willing to help fix this issue.

This discussion talks about this issue well maybe better than I did Dicussion on a similar issue

Wonderful tool you guys have built,Keep the great work up. 👍

@Ultra-Code Ultra-Code changed the title How to dynamically rebind reload to change event after unbinding it Question :How to dynamically rebind reload to change event after unbinding it Mar 12, 2022
@Ultra-Code Ultra-Code changed the title Question :How to dynamically rebind reload to change event after unbinding it Fzf should provide a way to dynamically rebind reload to change event after unbinding it Mar 12, 2022
@junegunn junegunn self-assigned this Apr 4, 2022
@junegunn
Copy link
Owner

junegunn commented Apr 4, 2022

Related: #2564

@junegunn
Copy link
Owner

junegunn commented Apr 4, 2022

Added rebind action to master branch.

#!/usr/bin/env bash

RG_PREFIX="rg --column --line-number --no-heading --color=always --smart-case "
INITIAL_QUERY="${*:-}"
IFS=: read -ra selected < <(
  FZF_DEFAULT_COMMAND="$RG_PREFIX $(printf %q "$INITIAL_QUERY")" \
  fzf --ansi \
      --color "hl:-1:underline,hl+:-1:underline:reverse" \
      --disabled --query "$INITIAL_QUERY" \
      --bind "change:reload:sleep 0.1; $RG_PREFIX {q} || true" \
      --bind "ctrl-f:unbind(change,ctrl-f)+change-prompt(2. fzf> )+enable-search+clear-query+rebind(ctrl-r)" \
      --bind "ctrl-r:unbind(ctrl-r)+change-prompt(1. ripgrep> )+disable-search+reload($RG_PREFIX {q} || true)+rebind(change,ctrl-f)" \
      --prompt '1. ripgrep> ' \
      --delimiter : \
      --preview 'bat --color=always {1} --highlight-line {2}' \
      --preview-window 'up,60%,border-bottom,+{2}+3/3,~3'
)
[ -n "${selected[0]}" ] && $EDITOR "${selected[0]}" "+${selected[1]}"

Please test it and let me know if it works as expected.

@Ultra-Code
Copy link
Author

@junegunn Thanks for taking the time to work on this. The rebind action works just as it should.

specv pushed a commit to specv/fzf that referenced this issue Apr 25, 2022
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

2 participants