1

I'm looking for a solution to searching history with fish when your history is full of long commands. I often have curl commands that contain json payloads in my history that I want to repeat, for example, and they're long enough that they don't fit into a single line, which makes it very hard to differentiate between them at a glance. My current solution is to type more of what I want but its pretty annoying.

shell history

Is there a way to make the history entries appear as they were executed, without reducing them to a single line? Is there a more clever solution I'm not thinking to ask for?

2 Answers 2

1

This was asked in Feature Request history multiline commands #2585, where two workaround were suggested by users:

  • Apply splitting manually.
    For example: set line (echo $history[1]) for the most recent history element.

  • Using sed to split lines in the file fish_history.

Unfortunately, this Feature Request was never marked as assigned to a developer.

0

As I commented on your closed SO version of this question, I had a similar question with Nushell. Unfortunately, I'm not aware of any fuzzy-finder in any shell (or non-shell) implementation that supports multi-line content in the finder itself.

It's not optimal, but there is a bit of workaround with fzf that I used with Nushell. The "Preview" function in fzf can modify the results, and you can use this to turn the history back into a properly formatted, multi-line (and even syntax-highlighted) result. In Nushell, that was with nu-highlight and Fish's built-in fish_indent --ansi essentially does the same thing (and a bit better, since it properly indents). That can at least turn the single-line output in the "Finder" into a multi-line preview that is more readable.

The general format of the command that you can test at the Fish command-line is:

commandline --replace $(history --null | fzf --read0 --preview "echo {} | fish_indent --ansi")

Also, this fzf plugin for Fish has the preview already enabled, but I would recommend setting the preview window to the right so that you can see as many lines as possible.

Screenshot of fzf with Fish

2
  • Thanks for the tips. The plugin requires versions of fzf and fish that aren't in the 22.04 Ubuntu repos. There's a ppa for fish but fzf is a pain to get later versions of. I tried your command but it doesn't seem to work out of the box for fish 3.7.1 Commented Apr 30 at 17:01
  • @AnthonyNaddeo What happens with the command on Fish 3.7.1? That's the same version I'm running, and I just tested it with fzf 0.29 (devel), which is the version currently in the Ubuntu 22.04 repo, and it seemed to work for me. The Fish version in the Ubuntu 22.04 repo is 3.3.1, and it's a one-character change if that's what's interfering - Just remove the $. I have noticed that fzf --preview picks up whatever the default shell is, so if you have both 3.3.1 and 3.7.1, it might still require the 3.3.1 syntax. Commented Apr 30 at 20:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .