1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-11-23 23:34:12 +03:00

git-tools.kak: use a single git command with subcommands

This commit is contained in:
Maxime Coste 2013-04-22 19:35:22 +02:00
parent 6df60f5d2f
commit c844f6f5cf

View File

@ -1,36 +1,47 @@
decl line-flag-list git_diff_flags
decl str docsclient decl str docsclient
def git-diff-update-buffer %{ %sh{ hook global WinSetOption filetype=git-log %{
added_lines="" addhl group git-log-highlight
removed_lines="" addhl -group git-log-highlight regex '^(commit) ([0-9a-f]+)$' 1:yellow 2:red
git diff -U0 $kak_bufname | { addhl -group git-log-highlight regex '^([a-zA-Z_-]+:) (.*?)$' 1:green 2:magenta
line=0 }
flags="0|red|."
while read; do
if [[ $REPLY =~ ^---.* ]]; then
continue
elif [[ $REPLY =~ ^@@.-[0-9]+(,[0-9]+)?.\+([0-9]+)(,[0-9]+)?.@@.* ]]; then
line=${BASH_REMATCH[2]}
elif [[ $REPLY =~ ^\+ ]]; then
flags="$flags;$line|green|+"
((line++))
elif [[ $REPLY =~ ^\- ]]; then
flags="$flags;$line|red|-"
fi
done
echo "setb git_diff_flags '$flags'"
}
}}
def git-diff-show %{ addhl flag_lines black git_diff_flags; git-diff-update-buffer } hook global WinSetOption filetype=(?!git-log).* %{
rmhl git-log-highlight
}
decl line-flag-list git_blame_flags decl line-flag-list git_blame_flags
decl line-flag-list git_diff_flags
def git-blame %{ def -shell-params git %{ %sh{
try %{ addhl flag_lines magenta git_blame_flags } catch %{} show_git_cmd_output() {
setb git_blame_flags '' local filetype
%sh{ ( case "$1" in
show) filetype=diff ;;
log) filetype=git-log ;;
esac
tmpfile=$(mktemp /tmp/kak-git-XXXXXX)
if git "$@" > ${tmpfile}; then
[[ -n "$kak_opt_docsclient" ]] && echo "eval -client '$kak_opt_docsclient' %{"
echo "edit! -scratch *git*
exec |cat<space>${tmpfile}<ret>gk
nop %sh{rm ${tmpfile}}
setb filetype '${filetype}'"
[[ -n "$kak_opt_docsclient" ]] && echo "}"
else
echo "echo %{git $@ failed, see *debug* buffer}"
rm ${tmpfile}
fi
}
run_git_blame() {
(
echo "eval -client '$kak_client' %{
try %{ addhl flag_lines magenta git_blame_flags } catch %{}
setb -buffer '$kak_bufname' git_blame_flags ''
}" | socat -u stdin UNIX-CONNECT:${kak_socket}
declare -A authors declare -A authors
declare -A dates declare -A dates
send_flags() { send_flags() {
@ -40,7 +51,7 @@ def git-blame %{
for (( i=1; $i < $count; i++ )); do for (( i=1; $i < $count; i++ )); do
flag="$flag;$(($line+$i))|black|$text" flag="$flag;$(($line+$i))|black|$text"
done done
echo "setb -add -buffer $kak_bufname git_blame_flags %{${flag}}" | socat -u stdin UNIX-CONNECT:${kak_socket} echo "setb -add -buffer '$kak_bufname' git_blame_flags %{${flag}}" | socat -u stdin UNIX-CONNECT:${kak_socket}
} }
git blame --incremental $kak_bufname | ( while read blame_line; do git blame --incremental $kak_bufname | ( while read blame_line; do
if [[ $blame_line =~ ([0-9a-f]{40}).([0-9]+).([0-9]+).([0-9]+) ]]; then if [[ $blame_line =~ ([0-9a-f]{40}).([0-9]+).([0-9]+).([0-9]+) ]]; then
@ -54,22 +65,38 @@ def git-blame %{
dates[$sha]="$(date -d @${BASH_REMATCH[1]} +'%F %T')" dates[$sha]="$(date -d @${BASH_REMATCH[1]} +'%F %T')"
fi fi
done; send_flags ) done; send_flags )
) >& /dev/null < /dev/null & } ) >& /dev/null < /dev/null &
} }
def -shell-params git-show %{ %sh{ update_diff() {
tmpfile=$(mktemp /tmp/kak-git-show-XXXXXX) git diff -U0 $kak_bufname | {
if git show "$@" > ${tmpfile}; then local line=0
[[ -n "$kak_opt_docsclient" ]] && echo "eval -client '$kak_opt_docsclient' %{" local flags="0|red|."
while read; do
if [[ $REPLY =~ ^---.* ]]; then
continue
elif [[ $REPLY =~ ^@@.-[0-9]+(,[0-9]+)?.\+([0-9]+)(,[0-9]+)?.@@.* ]]; then
line=${BASH_REMATCH[2]}
elif [[ $REPLY =~ ^\+ ]]; then
flags="$flags;$line|green|+"
((line++))
elif [[ $REPLY =~ ^\- ]]; then
flags="$flags;$line|red|-"
fi
done
echo "setb git_diff_flags '$flags'"
}
}
echo "edit! -scratch *git-show* case "$1" in
exec |cat<space>${tmpfile}<ret>gk show|log) show_git_cmd_output "$@" ;;
nop %sh{rm ${tmpfile}} blame) run_git_blame ;;
setb filetype diff" show-diff)
echo "try %{ addhl flag_lines black git_diff_flags } catch %{}"
update_diff
;;
update-diff) update_diff ;;
*) echo "echo %{unknown git command '$1'}"; exit ;;
esac
[[ -n "$kak_opt_docsclient" ]] && echo "}"
else
echo "echo %{git show '$@' failed, see *debug* buffer}"
rm ${tmpfile}
fi
}} }}