Browse Source

zsh: fzf jj commit picker

raylu 1 tháng trước cách đây
mục cha
commit
e2cd354a11
1 tập tin đã thay đổi với 17 bổ sung4 xóa
  1. 17 4
      zshrc

+ 17 - 4
zshrc

@@ -178,10 +178,23 @@ if builtin which fzf > /dev/null; then
 
 	__fzf_git_commit_sha() {
 		setopt localoptions pipefail no_aliases 2> /dev/null
-		git log --color=always -n 50 --format='%C(auto)%h%d %s %C(black)%C(bold)%cr' |
-			FZF_DEFAULT_OPTS="--ansi --no-sort --tiebreak=index --reverse \
-				--preview 'git show --color=always {1}' ${FZF_DEFAULT_OPTS-}" $(__fzfcmd) -m "$@" |
-			sed -r -e 's/([0-9a-f]+) .+/\1/' -e 's/.+ ([0-9a-f]+)/\1/'
+		if jj root &> /dev/null; then
+			jj --ignore-working-copy --color=always log --no-graph \
+				-T 'if(root, format_root_commit(self), label(
+						if(current_working_copy, "working_copy"),
+						format_short_commit_header(self) ++ "\n" ++ if(description, description.first_line(),
+							label(if(empty, "empty"), description_placeholder)
+						)
+					)) ++ "\x00"' |
+				$(__fzfcmd) --read0 --ansi --raw --no-sort --reverse --highlight-line \
+					--height ${FZF_TMUX_HEIGHT:-40%} --accept-nth 1 \
+					--preview='jj --ignore-working-copy --color=always show --stat {1}'
+		else
+			git log --color=always -n 50 --format='%C(auto)%h%d %s %C(black)%C(bold)%cr' |
+				FZF_DEFAULT_OPTS="--ansi --no-sort --tiebreak=index --reverse \
+					--preview 'git show --color=always {1}' ${FZF_DEFAULT_OPTS-}" $(__fzfcmd) -m "$@" |
+				sed -r -e 's/([0-9a-f]+) .+/\1/' -e 's/.+ ([0-9a-f]+)/\1/'
+		fi
 	}
 	fzf-git-commit-sha-widget() {
 		LBUFFER="${LBUFFER}$(__fzf_git_commit_sha)"