dotfiles/fish/functions/_fzf_search_history.fish
2022-11-27 14:20:25 +08:00

24 lines
969 B
Fish

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 │ " |
_fzf_wrapper --read0 \
--tiebreak=index \
--query=(commandline) \
# preview current command using fish_ident in a window at the bottom 3 lines tall
--preview="echo -- {4..} | fish_indent --ansi" \
--preview-window="bottom:3:wrap" \
$fzf_history_opts |
string collect
)
if test $status -eq 0
set command_selected (string split --max 1 " │ " $command_with_ts)[2]
commandline --replace -- $command_selected
end
commandline --function repaint
end