From e901781ab3c9eb6ee3b63d77590c3dac0f9580f2 Mon Sep 17 00:00:00 2001 From: siinus Date: Wed, 13 Mar 2024 23:43:19 +0200 Subject: [PATCH] Remove zaw, add fzf --- zsh/.zshrc | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/zsh/.zshrc b/zsh/.zshrc index 1b106c9..2abd0d4 100644 --- a/zsh/.zshrc +++ b/zsh/.zshrc @@ -1,9 +1,37 @@ source /usr/share/zaw/zaw.zsh -bindkey '^R' zaw-history -bindkey -M filterselect '^R' down-line-or-history -bindkey -M filterselect '^S' up-line-or-history -bindkey -M filterselect '^E' accept-search +# fzf +xsource /usr/share/fzf/key-bindings.zsh +xsource /usr/share/fzf/completion.zsh + +# fzf history search with support for Ctrl+E history edit like with zaw widget before +if typeset -f fzf-history-widget > /dev/null; then + # Copied form key-bindings.zsh + # CTRL-R - Paste the selected command from history into the command line + fzf-history-widget() { + local selected num + setopt localoptions noglobsubst noposixbuiltins pipefail no_aliases 2> /dev/null + selected=( $(fc -rl 1 | perl -ne 'print if !$seen{(/^\s*[0-9]+\**\s+(.*)/, $1)}++' | + FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} $FZF_DEFAULT_OPTS -n2..,.. --tiebreak=index --bind=ctrl-r:toggle-sort --expect=ctrl-e $FZF_CTRL_R_OPTS --query=${(qqq)LBUFFER} +m" $(__fzfcmd)) ) + local ret=$? + if [ -n "$selected" ]; then + local accept=0 + if [[ $selected[1] == ctrl-e ]]; then + accept=1 + shift selected + fi + num=$selected[1] + if [ -n "$num" ]; then + zle vi-fetch-history -n $num + [[ $accept = 0 ]] && zle accept-line + fi + fi + zle reset-prompt + return $ret + } + zle -N fzf-history-widget + bindkey '^R' fzf-history-widget +fi zstyle ':filter-select:highlight' matched fg=green zstyle ':filter-select' max-lines 3