فهرست منبع

zsh: fzf-based giw

raylu 1 سال پیش
والد
کامیت
b1e13e5e6d
1فایلهای تغییر یافته به همراه17 افزوده شده و 1 حذف شده
  1. 17 1
      zshrc

+ 17 - 1
zshrc

@@ -83,7 +83,6 @@ alias gil='git log --graph --abbrev-commit --stat --summary -C --decorate --date
 alias gib='git branch'
 alias gis='git status'
 alias gid='git diff -C --date=local'
-alias giw='git show -C --date=local --decorate'
 alias gic='git checkout'
 alias giu='git reset HEAD\^'
 alias gn='git number'
@@ -208,6 +207,23 @@ if [ -x /usr/bin/fzf ]; then
 	}
 	zle -N fzf-rg-widget
 	bindkey '^S' fzf-rg-widget
+
+	giw() {
+		local commit=${1:-HEAD}
+		git diff-tree --color=always --stat --no-commit-id $commit | sed '$d' | cut -c 2- | \
+			fzf --filepath-word --ansi --layout=reverse --bind enter:abort \
+				--header="$(git show --date=local --decorate --shortstat --color=always $commit)" \
+				--preview-window='right,<110(down,70%)' \
+				--preview="git diff-tree --patch --no-commit-id --color=always $commit {1} | delta" \
+				--bind tab:toggle-preview,ctrl-y:preview-up,ctrl-e:preview-down \
+				--bind ctrl-b:preview-page-up,ctrl-f:preview-page-down \
+				--bind ctrl-u:preview-half-page-up,ctrl-d:preview-half-page-down \
+				--bind="ctrl-o:execute(git diff-tree --patch --no-commit-id --color=always $commit {1} | delta --paging=always)" \
+				--bind="ctrl-s:execute(git show -C --date=local --decorate $commit)"
+
+	}
+else
+	alias giw='git show -C --date=local --decorate'
 fi
 
 stty stop undef