From f4b3510b140c5feec0d37db13be43dd410a6f1c3 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sun, 31 Mar 2013 14:52:09 +0200 Subject: [PATCH] add git-blame command to git-tools.kak --- src/rc/git-tools.kak | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/rc/git-tools.kak b/src/rc/git-tools.kak index 9ac8c2454..3052a0a77 100644 --- a/src/rc/git-tools.kak +++ b/src/rc/git-tools.kak @@ -23,3 +23,32 @@ def git-diff-update-buffer %{ %sh{ }} def git-diff-show %{ addhl flag_lines black git_diff_flags; git-diff-update-buffer } + +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 + send_flags() { + if [[ -z "$line" ]]; then return; fi + text="${sha:0:8} ${authors[$sha]}" + flag="$line:black:$text" + for (( i=1; $i < $count; i++ )); do + flag="$flag,$(($line+$i)):black:$text" + 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]} + fi + done; send_flags ) + ) >& /dev/null < /dev/null & } +}