PatrickF1 / fzf.fish

πŸ”πŸŸ Fzf plugin for Fish
MIT License
2k stars 81 forks source link

Command history not working #312

Closed anon-legion closed 11 months ago

anon-legion commented 11 months ago

Before proceeding...

Describe the bug

ctrl+r (command history) only creates a new line above my prompt and does not show any command history.

fzf-fish_command_history_bug

Steps to reproduce

Press ctrl+r

Environment

Versions installed:

Which, if any, configuration variables such as fzf_preview_file_cmd are set?

I am using defaults except for fzf_configure_bindings --directory=\cf set in my config.fish

Additional context

This is a fresh install for a brand new S76 laptop. If I unbind command history by doing fzf_configure_bindings --history=, triggers a different looking command history like so: fzf_configure_bindings_--history=

PatrickF1 commented 11 months ago

Hi,

anon-legion commented 11 months ago

Hi @PatrickF1,

  1. The only non-default fzf.fish bind that I configured is Directory, set to ctrl+f. The results of bind: Screenshot from 2023-11-04 10-06-00

  2. GNOME Terminal > Preferences > Shortcuts has no binds for Ctrl+R, the only commands that start with ctrl are Zoom in (ctrl++), Zoom out (ctrl+-), Normal Size (ctrl+0), Switch to previous tab (ctrl+page up), and Switch to next tab (ctrl+page down). The rest start with either shift, alt, or are disabled

  3. Yes the other fzf.fish commands work as expect. Directory, Process, etc... I am only having issue with History

PatrickF1 commented 11 months ago

Okay. Can you try binding Ctrl+R to ls and see if it triggers ls successfully?

And also can you run history and make sure it’s not empty?

anon-legion commented 11 months ago

I bind ctrl+r to ls in config.fish like so: Screenshot from 2023-11-05 08-49-06

Pressing ctrl+r triggers ls as expected: Screenshot from 2023-11-05 08-52-04

Running history shows history is not empty: Screenshot from 2023-11-05 08-53-52

PatrickF1 commented 11 months ago

Wow, very strange indeed. Can you try using a different terminal emulator and seeing it it works there? I'm trying to isolate the bug.

And if that still doesn't work, can you go into _fzf_search_history and overwrite the file to do something really simply like this

function _fzf_search_history
    set -f commands_selected (ls | _fzf_wrapper)
    if test $status -eq 0
        commandline --replace -- $commands_selected
    end

    commandline --function repaint
end

You can the path to the file is by running functions _fzf_search_history.

Sorry you have to get your hands dirty. This is a tricky bug.

anon-legion commented 11 months ago
  1. Tried using a different terminal (Guake Terminal) and the same issue persist, pressing ctrl+r creates a newline above my prompt: Screenshot from 2023-11-05 20-23-46

  2. Copy pasted suggested code to _fzf_search_history.fish and overwrote existing code like so: Screenshot from 2023-11-05 20-47-44

The results of pressing ctrl+r now yields the contents of the path directory: Screenshot from 2023-11-05 20-51-45

PatrickF1 commented 11 months ago

Ok we've isolated the issue to something within _fzf_search_history.

One more test: this time replace _fzf_search_history with

function _fzf_search_history
    set -f commands_selected (history | _fzf_wrapper)
    if test $status -eq 0
        commandline --replace -- $commands_selected
    end

    commandline --function repaint
end

does that work?

anon-legion commented 11 months ago

I copy pasted your code and replaced _fzf_search_history as you requested: Screenshot from 2023-11-06 20-44-43

Pressing ctrl+r now shows command history like so: Screenshot from 2023-11-06 20-44-15

Did we fix it? Or are we close?

PatrickF1 commented 11 months ago

I think we're close-ish. We've eliminated a lot of things as the problem and know the problem is something in _fzf_search_history. Still don't know exactly what it is though.

You seem like a very competent user. Would you prefer to play around with _fzf_search_history and debug it yourself now, or do you want me to continue debugging over this conversation? Obviously it'll be more thinking for you to do the former but it'll also be way faster.

anon-legion commented 11 months ago

I will give it a shot. I'll see what I can do and work on it this weekend when I have no work so I have plenty time to sit down and thoroughly debug the issue. If I have any questions or if I find the solution I will be posting it here.

anon-legion commented 11 months ago

Hi @PatrickF1, I Have isolated the issue to the --scheme=history option of the _fzf_wrapper function. Currently my _fzf_search_history.fish is exactly like the default fish function except with the --scheme=history commented out like so:

function _fzf_search_history --description "Search command history. Replace the command line with the selected command."
    if test -z "$fish_private_mode"
        builtin history merge
    end

    if not set --query fzf_history_time_format
        set -f fzf_history_time_format "%m-%d %H:%M:%S"
    end

    set -f time_prefix_regex '^.*? β”‚ '

    set -f commands_selected (
        builtin history --null --show-time="$fzf_history_time_format β”‚ " |
        _fzf_wrapper --read0 \
            --print0 \
            --multi \
        #     --scheme=history \
            --prompt="History> " \
            --query=(commandline) \
            --preview="string replace --regex '$time_prefix_regex' '' -- {} | fish_indent --ansi" \
            --preview-window="bottom:3:wrap" \
            $fzf_history_opts |
        string split0 |
        string replace --regex $time_prefix_regex ''
    )

    if test $status -eq 0
        commandline --replace -- $commands_selected
    end

    commandline --function repaint
end

Now pressing ctrl+r show the command history and it looks to me like its working normally now? What was that option supposed to do? Screenshot from 2023-11-11 18-54-16

PatrickF1 commented 11 months ago

https://github.com/PatrickF1/fzf.fish/pull/302 is where it was added. It makes the scoring algorithm better for chronological list. Your issue might be that you're not on the latest version of fzf, but for some reason the error isn't showing up!

anon-legion commented 11 months ago

Oh, please pardon me. I installed fzf using apt repo and I did not realize until I looked at "Packaging status" that the version it downloads for Ubuntu 22.04 is very far behind (0.29.0), I should have not made any assumptions regarding the recency of the package's version. I have downloaded and built fzf from source and I am now on the latest version (0.43.0). I have also uncommented the -scheme=history option in _fzf_search_history.fish and now everything works as expected. Thank you for your patience.

PatrickF1 commented 11 months ago

No problem, it happens! I am also very confused why it doesn't error and just outputs a newline. Let me know if you have any ideas!