# bash-style reverse-search-history (i.e. reverse-i-search)
if [[ -v commands[fzf] ]] {
function _history-incremental-pattern-search-fzf {
- l=(${(f)"$(fc -li -1 0 | fzf -e -m -n 1 +s --preview-window=hidden ${BUFFER:+-q $BUFFER})"})
+ fc -AI
+ # XXX: this shit is cursed and sometimes doesn't work
+ # TODO: remove doesn't work over newlines, fzf replaces them with \n,
+ # and sed of course hates newlines and would need to be massaged
+ # TODO: interactive history refresh... can't get zsh to load histfile:
+ # +reload(HISTFILE='"$h HISTSIZE=$HISTSIZE SAVEHIST=$SAVEHIST \$0 +Z -dfimc 'setopt EXTENDED_HISTORY;fc -R \$HISTFILE;$c' </dev/null 2>&1)" \
+ local c='fc -lt%F -1 0'
+ local h="'${HISTFILE//\'/\'\\\'\'}'"
+ local l=(${(f)"$($=c | fzf \
+ --scheme=history -e -n 1,3.. \
+ +s \
+ -m --bind 'ctrl-d:execute-silent(sed -i -f <(
+ sed -Ee '\''s/[$*.[\^/]/\\&/g;s~.*~/^\\(: [0-9]\\+:[0-9]\\+;\\)\\?&$/d~'\'' {+f3..}
+ ) '$h')+abort' \
+ --preview-window=hidden --height=20% \
+ --with-shell "${0:a} -dfc" \
+ ${BUFFER:+-q $BUFFER})"})
+ # XXX: this sucks, I hate this. no other way to flush internal history?
+ HISTFILE= HISTSIZE=0 fc -p $HISTFILE $HISTSIZE $SAVEHIST
l=$(for x ("${l[@]}") { echo ${${=x}:3}; })
BUFFER="$l"
+ zle reset-prompt
}
zle -N _history-incremental-pattern-search-fzf
bindkey '^R' _history-incremental-pattern-search-fzf