How to filter history results to items starting with specific string using ^ #169
-
I can't search the history results for history items beginning with a specific string. I think I should be able to press crtl+R then type the caret symbol followed by one or several characters and this should constrain the results to only the history items beginning with those characters - per fzf usage. (https://github.com/junegunn/fzf/blob/master/README.md#search-syntax.) What happens is that because each line starts with a time string, it is this time string that fzf starts searching in, not in the actual history command lines. I find this particularly problematic because I have not yet found a way to interactively recall Fish history "lines starting with" from just Fish itself. If I might suggest simply removing the time at the beginning of each line ? Just personally I have little use for it... For reference, I hacked function __fzf_search_history --description "Search command history. Replace the command line with the selected command."
# history merge incorporates history changes from other fish sessions
builtin history merge
set command_with_ts (
# Reference https://devhints.io/strftime to understand strftime format symbols
#builtin history --null --show-time="%m-%d %H:%M:%S | " |
builtin history --null |
fzf --read0 --tiebreak=index --query=(commandline) \
# preview current command in a window at the bottom 3 lines tall
--preview="echo {4..}" \
--preview-window="bottom:3:wrap" |
string collect
)
if test $status -eq 0
#set command_selected (string split --max 1 " | " $command_with_ts)[2]
#commandline --replace -- $command_selected
commandline --replace -- $command_with_ts
end
commandline --function repaint
end Thanks and all the best ! Environment
Not sure where to find fzf.fish version. Installed today ( |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments
-
@maciderio Hi! While you may not have use for it, I do and I suspect so do many other people so I'm afraid I won't be removing it. Let me think of another solution, however. |
Beta Was this translation helpful? Give feedback.
-
Ok I found a solution. All you need to do is pass in |
Beta Was this translation helpful? Give feedback.
-
@maciderio FYI with #140, making this change is even easier through the newly introduced variable |
Beta Was this translation helpful? Give feedback.
-
This is a great solution ! Thank you for such a fast change and a great project ! |
Beta Was this translation helpful? Give feedback.
Ok I found a solution. All you need to do is pass in
--nth="4.."
via FZF_DEFAULT_OPTS and the history string won't be searched. To do this, try following the instructions here https://github.com/PatrickF1/fzf.fish/wiki/FAQ#how-can-i-pass-fzf-options-specific-to-one-command.In the meantime, when I finally have time, I'm going to implement passing in custom fzf opts to each command to make this process easier.