浏览代码

zsh: add fzf-rg-widget

raylu 1 年之前
父节点
当前提交
fbd240f599
共有 1 个文件被更改,包括 21 次插入0 次删除
  1. 21 0
      zshrc

+ 21 - 0
zshrc

@@ -187,6 +187,27 @@ if [ -x /usr/bin/fzf ]; then
 	}
 	zle -N fzf-pid-widget
 	bindkey '^O' fzf-pid-widget
+
+	__fzf_rg() {
+		setopt localoptions pipefail no_aliases 2> /dev/null
+		RELOAD='reload:rg --column --color=always --smart-case {q} || :'
+		$(__fzfcmd) --disabled --ansi --multi \
+				--bind "start:$RELOAD" --bind "change:$RELOAD" \
+				--bind 'alt-a:select-all,alt-d:deselect-all,ctrl-/:toggle-preview' \
+				--delimiter : \
+				--preview 'bat --style=full --color=always --highlight-line {2} {1}' \
+				--preview-window '~4,+{2}+4/3,<80(up)' \
+				--query "$*" |
+			cut -d: -f1
+		}
+		fzf-rg-widget() {
+		LBUFFER="${LBUFFER}$(__fzf_rg)"
+		local ret=$?
+		zle reset-prompt
+		return $ret
+	}
+	zle -N fzf-rg-widget
+	bindkey '^S' fzf-rg-widget
 fi
 
 stty stop undef