1
0
Эх сурвалжийг харах

zsh: ctrl+h fzf branch widget

raylu 1 жил өмнө
parent
commit
58b6fdc60d
1 өөрчлөгдсөн 18 нэмэгдсэн , 0 устгасан
  1. 18 0
      zshrc

+ 18 - 0
zshrc

@@ -178,6 +178,24 @@ if [ -x /usr/bin/fzf ]; then
 	zle -N fzf-git-commit-sha-widget
 	bindkey '^G' fzf-git-commit-sha-widget
 
+	__fzf_git_branch() {
+		setopt localoptions pipefail no_aliases 2> /dev/null
+		git branch --all --color=always \
+			--format='%(if)%(HEAD)%(then)%(color:bold green)%(else)%(if:equals=refs/remotes)%(refname:rstrip=-2)%(then)%(color:red)%(end)%(end)%(refname:short)' |
+			FZF_DEFAULT_OPTS="--ansi --no-sort --tiebreak=index --reverse ${FZF_DEFAULT_OPTS-}" \
+				$(__fzfcmd) \
+				--preview 'git log --color=always --abbrev-commit --stat --summary -C --decorate --date=local {1} --max-count=20' \
+				--height ${FZF_TMUX_HEIGHT:-40%} "$@"
+	}
+	fzf-git-branch-widget() {
+		LBUFFER="${LBUFFER}$(__fzf_git_branch)"
+		local ret=$?
+		zle reset-prompt
+		return $ret
+	}
+	zle -N fzf-git-branch-widget
+	bindkey '^H' fzf-git-branch-widget
+
 	__fzf_pid() {
 		setopt localoptions pipefail no_aliases 2> /dev/null
 		ps axo pid,start,user,command |