2013-03-29 19:37:35 +01:00
|
|
|
decl line-flag-list git_diff_flags
|
|
|
|
|
|
|
|
def git-diff-update-buffer %{ %sh{
|
|
|
|
added_lines=""
|
|
|
|
removed_lines=""
|
|
|
|
git diff -U0 $kak_bufname | {
|
|
|
|
line=0
|
2013-04-11 22:41:43 +02:00
|
|
|
flags="0|red|."
|
2013-03-29 19:37:35 +01:00
|
|
|
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
|
2013-04-11 22:41:43 +02:00
|
|
|
flags="$flags;$line|green|+"
|
2013-03-29 19:37:35 +01:00
|
|
|
((line++))
|
|
|
|
elif [[ $REPLY =~ ^\- ]]; then
|
2013-04-11 22:41:43 +02:00
|
|
|
flags="$flags;$line|red|-"
|
2013-03-29 19:37:35 +01:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
echo "setb git_diff_flags '$flags'"
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
|
|
|
|
def git-diff-show %{ addhl flag_lines black git_diff_flags; git-diff-update-buffer }
|
2013-03-31 14:52:09 +02:00
|
|
|
|
|
|
|
decl line-flag-list git_blame_flags
|
|
|
|
|
|
|
|
def git-blame %{
|
|
|
|
try %{ addhl flag_lines magenta git_blame_flags } catch %{}
|
|
|
|
setb git_blame_flags ''
|
|
|
|
%sh{ (
|
|
|
|
declare -A authors
|
2013-04-02 18:57:02 +02:00
|
|
|
declare -A dates
|
2013-03-31 14:52:09 +02:00
|
|
|
send_flags() {
|
|
|
|
if [[ -z "$line" ]]; then return; fi
|
2013-04-02 18:57:02 +02:00
|
|
|
text="${sha:0:8} ${dates[$sha]} ${authors[$sha]}"
|
|
|
|
flag="$line|black|$text"
|
2013-03-31 14:52:09 +02:00
|
|
|
for (( i=1; $i < $count; i++ )); do
|
2013-04-02 18:56:09 +02:00
|
|
|
flag="$flag;$(($line+$i))|black|$text"
|
2013-03-31 14:52:09 +02:00
|
|
|
done
|
|
|
|
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
|
|
|
|
if [[ $blame_line =~ ([0-9a-f]{40}).([0-9]+).([0-9]+).([0-9]+) ]]; then
|
|
|
|
send_flags
|
|
|
|
sha=${BASH_REMATCH[1]}
|
|
|
|
line=${BASH_REMATCH[3]}
|
|
|
|
count=${BASH_REMATCH[4]}
|
|
|
|
elif [[ $blame_line =~ author[^-](.*) ]]; then
|
|
|
|
authors[$sha]=${BASH_REMATCH[1]}
|
2013-04-02 18:57:02 +02:00
|
|
|
elif [[ $blame_line =~ author-time.([0-9]*) ]]; then
|
|
|
|
dates[$sha]="$(date -d @${BASH_REMATCH[1]} +'%F %T')"
|
2013-03-31 14:52:09 +02:00
|
|
|
fi
|
|
|
|
done; send_flags )
|
|
|
|
) >& /dev/null < /dev/null & }
|
|
|
|
}
|