junegunn / fzf

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

History search not working #3904

Closed 0xBigBoss closed 2 days ago

0xBigBoss commented 3 days ago

Checklist

Output of fzf --version

0.53.0 (c4a9ccd)

OS

Shell

Problem / Steps to reproduce

Press CTRL-R to search through history. Press enter to select an entry. Nothing is entered into the terminal. See the screen recording for exactly what's happening. You can see the bug at around 00:27.

https://github.com/junegunn/fzf/assets/95193764/98c71930-e229-4766-9719-73e6e962374a

junegunn commented 3 days ago

What's the version of your zsh?

zsh --version

Is the problem still reproducible on zsh without any configuration?

zsh -d -f

source <(fzf --zsh)

# Or if fzf is not in your $PATH
source <(~/.fzf/bin/fzf --zsh)
0xBigBoss commented 3 days ago

same issue. tried with the homebrew zsh and apple zsh.

zsh --version
zsh 5.9 (x86_64-apple-darwin23.0)
opt/homebrew/bin/zsh --version
zsh 5.9 (arm-apple-darwin23.0.0)

https://github.com/junegunn/fzf/assets/95193764/06c8b911-bcc9-4ae1-990d-a444a592f3e9

LangLangBart commented 3 days ago

Could you share the output when running the following commands one after another?

# Improved trace prompt
PS4='%B%F{0}+ %D{%T:%3.} %2N:%i%f%b '
# Clears current shell history to minimize debug output
fc -p =(<<<"")

unsetopt KSH_OPTION_PRINT
setopt
fzf --version
source <(fzf --zsh)
# Enable tracing for the function
typeset -fT fzf-history-widget
# Press Ctrl-R, then Enter
junegunn commented 2 days ago

CTRL-R uses Perl since 0.53.0. Could this be a problem with the Perl installation? perl --version?

0xBigBoss commented 2 days ago

here is the trace outputs

~/.fzf tags/0.53.0 45s
❯ PS4='%B%F{0}+ %D{%T:%3.} %2N:%i%f%b '

~/.fzf tags/0.53.0
❯ fc -p =(<<<"")

~/.fzf tags/0.53.0
❯ unsetopt KSH_OPTION_PRINT

~/.fzf tags/0.53.0
❯ setopt
alwaystoend
autocd
autopushd
combiningchars
completeinword
extendedhistory
noflowcontrol
histexpiredupsfirst
histignoredups
histignorespace
histverify
interactive
interactivecomments
login
longlistjobs
monitor
nopromptcr
nopromptsp
promptsubst
pushdignoredups
pushdminus
sharehistory
shinstdin
zle

~/.fzf tags/0.53.0
❯ fzf --version

0.53.0 (c4a9ccd)

~/.fzf tags/0.53.0
❯ source <(fzf --zsh)

~/.fzf tags/0.53.0
❯ typeset -fT fzf-history-widget

~/.fzf tags/0.53.0
❯ + 17:18:46:611 fzf-history-widget:1 local selected num
+ 17:18:46:611 fzf-history-widget:2 setopt localoptions noglobsubst noposixbuiltins pipefail no_aliases
+ 17:18:46:612 fzf-history-widget:5 zmodload -F zsh/parameter p:history
+ 17:18:46:612 fzf-history-widget:5 ((  22  ))
+ 17:18:46:612 fzf-history-widget:6 selected=+ 17:18:46:616 fzf-history-widget:6 printf '%1$s\t%2$s\000' 6 $'typeset -fT fzf-history-widget\n' 5 $'source <(fzf --zsh)\n' 4 $'fzf --version\n' 3 setopt 2 $'unsetopt KSH_OPTION_PRINT\n' 1 ''
+ 17:18:46:612 fzf-history-widget:6 selected=+ 17:18:46:617 fzf-history-widget:7 perl -0 -ne 'if (!$seen{(/^\s*[0-9]+\**\s+(.*)/, $1)}++) { s/\n/\n\t/gm; print; }'
+ 17:18:46:612 fzf-history-widget:6 selected=+ 17:18:46:617 fzf-history-widget:8 __fzfcmd
+ 17:18:46:612 fzf-history-widget:6 selected=+ 17:18:46:619 fzf-history-widget:8 FZF_DEFAULT_OPTS=+ 17:18:46:620 fzf-history-widget:8 __fzf_defaults '' '-n2..,.. --scheme=history --bind=ctrl-r:toggle-sort --highlight-line  --query="" +m --read0'
+ 17:18:46:619 fzf-history-widget:8 FZF_DEFAULT_OPTS=$'--height 40% --bind=ctrl-z:ignore \n -n2..,.. --scheme=history --bind=ctrl-r:toggle-sort --highlight-line  --query="" +m --read0' FZF_DEFAULT_OPTS_FILE='' fzf
+ 17:18:46:612 fzf-history-widget:6 selected=$'4\tfzf --version\n\t'
+ 17:18:49:857 fzf-history-widget:15 local ret=0
+ 17:18:49:857 fzf-history-widget:16 [ -n $'4\tfzf --version\n\t' ']'
+ 17:18:49:857 fzf-history-widget:17 num=+ 17:18:49:857 fzf-history-widget:17 num=+ 17:18:49:862 fzf-history-widget:17 awk '{print $1; exit}'
+ 17:18:49:862 fzf-history-widget:17 grep -o '^[1-9][0-9]*'
+ 17:18:49:857 fzf-history-widget:17 num=$'\C-[[01;31m\C-[[K4\C-[[m\C-[[K'
+ 17:18:49:868 fzf-history-widget:18 zle vi-fetch-history -n $'\C-[[01;31m\C-[[K4\C-[[m\C-[[K'
+ 17:18:49:868 fzf-history-widget:23 zle reset-prompt
~/.fzf tags/0.53.0
❯

I tried with apple perl (v5.34.1) and homebrew perl (v5.38.2).

junegunn commented 2 days ago

It looks like your "grep" is injecting color codes to the output when it shouldn't. What is the output of type grep?

0xBigBoss commented 2 days ago

@junegunn great find. I have GREP_OPTIONS set.

GREP_OPTIONS=--color=always -I --exclude=tags --exclude-dir={.svn,.git,target}

grep is an alias for grep --color=auto --exclude-dir={.bzr,CVS,.git,.hg,.svn,.idea,.tox}
grep --version
grep (BSD grep, GNU compatible) 2.6.0-FreeBSD

Unsetting it and fzf works again.