[zsh] add history search with fzf

This commit is contained in:
Dmytro Meleshko 2019-09-08 15:47:38 +03:00
parent 3c8dd0f9f2
commit d184233b67
3 changed files with 24 additions and 2 deletions

View file

@ -43,7 +43,7 @@ _palette_widget() {
# try to fill in a placeholder if there're any, otherwise pick a snippet # try to fill in a placeholder if there're any, otherwise pick a snippet
if ! _palette_fill_in_placeholder; then if ! _palette_fill_in_placeholder; then
local selected local selected
if selected="$(_palette_parse_tldr_pages | fzf --ansi --cycle --height 50% --reverse)" if selected="$(_palette_parse_tldr_pages | fzf --height 40% --reverse --ansi)"
then then
# paste selected snippet without its description # paste selected snippet without its description
zle -U "${selected%%$PALETTE_SNIPPET_COMMENT*}" zle -U "${selected%%$PALETTE_SNIPPET_COMMENT*}"

22
zsh/zle.zsh Normal file
View file

@ -0,0 +1,22 @@
#!/usr/bin/env zsh
if command_exists fzf; then
# taken from https://github.com/junegunn/fzf/blob/master/shell/key-bindings.zsh
fzf-history-widget() {
setopt localoptions pipefail
local selected
selected=(
$(fc -rl 1 |
fzf --height=40% --reverse --nth=2.. --tiebreak=index --query="$LBUFFER")
)
local fzf_ret="$?"
if (( ${#selected} )); then
zle vi-fetch-history -n "${selected[1]}"
fi
zle reset-prompt
return "$fzf_ret"
}
zle -N fzf-history-widget
bindkey '^[r' fzf-history-widget
fi

View file

@ -2,7 +2,7 @@
ZSH_DOTFILES="${0:h}" ZSH_DOTFILES="${0:h}"
for script in functions path env plugins aliases palette prompt; do for script in functions path env plugins aliases zle palette prompt; do
source "$ZSH_DOTFILES/$script.zsh" source "$ZSH_DOTFILES/$script.zsh"
source_if_exists "$ZSH_DOTFILES/custom/$script.zsh" source_if_exists "$ZSH_DOTFILES/custom/$script.zsh"
done done