port git-tools.kak from bash to posix shell + posix awk

This commit is contained in:
Maxime Coste 2014-03-25 09:25:37 +00:00
parent b677f9da63
commit 709dc87fcc

View File

@ -40,52 +40,57 @@ def -shell-params git %{ %sh{
( (
echo "eval -client '$kak_client' %{ echo "eval -client '$kak_client' %{
try %{ addhl flag_lines magenta git_blame_flags } try %{ addhl flag_lines magenta git_blame_flags }
set buffer=$kak_buffile git_blame_flags '' set buffer=$kak_bufname git_blame_flags ''
}" | kak -p ${kak_session} }" | kak -p ${kak_session}
declare -A authors git blame --incremental ${kak_buffile} | awk -e '
declare -A dates function send_flags(text, flag, i) {
send_flags() { if (line == "") { return; }
if [ -z "$line" ]; then return; fi text=substr(sha,1,8) " " dates[sha] " " authors[sha]
text=$(echo "${sha:0:8} ${dates[$sha]} ${authors[$sha]}" | sed -e 's/:/\\:/g') gsub(":", "\\:", text)
flag="$line|black|$text" flag=line "|black|" text
for (( i=1; $i < $count; i++ )); do for ( i=1; i < count; i++ ) {
flag="$flag:$(($line+$i))|black|$text" flag=flag ":" line+i "|black|" text
done }
echo "set -add buffer=$kak_buffile git_blame_flags %{${flag}}" | kak -p ${kak_session} cmd = "kak -p " ENVIRON["kak_session"]
} print "set -add buffer=" ENVIRON["kak_bufname"] " git_blame_flags %{" flag "}" | cmd
git blame --incremental $kak_buffile | ( while read blame_line; do close(cmd)
if [[ $blame_line =~ ([0-9a-f]{40}).([0-9]+).([0-9]+).([0-9]+) ]]; then }
send_flags /^([0-9a-f]{40}) ([0-9]+) ([0-9]+) ([0-9]+)/ {
sha=${BASH_REMATCH[1]} send_flags()
line=${BASH_REMATCH[3]} sha=$1
count=${BASH_REMATCH[4]} line=$3
elif [[ $blame_line =~ author[^-](.*) ]]; then count=$4
authors[$sha]=${BASH_REMATCH[1]} }
elif [[ $blame_line =~ author-time.([0-9]*) ]]; then /^author / { authors[sha]=substr($0,8) }
dates[$sha]="$(date -d @${BASH_REMATCH[1]} +'%F %T')" /^author-time ([0-9]*)/ {
fi cmd = "date -d @" $2 " +\"%F %T\""
done; send_flags ) cmd | getline dates[sha]
) >& /dev/null < /dev/null & }
END { send_flags(); }'
) > /dev/null 2>&1 < /dev/null &
} }
update_diff() { update_diff() {
git diff -U0 $kak_buffile | { git diff -U0 $kak_buffile | awk -e '
local line=0 BEGIN {
local flags="0|red|." line=0
while read; do flags="0|red|."
if [[ $REPLY =~ ^---.* ]]; then }
continue /^---.*/ {}
elif [[ $REPLY =~ ^@@.-[0-9]+(,[0-9]+)?.\+([0-9]+)(,[0-9]+)?.@@.* ]]; then /^@@ -[0-9]+(,[0-9]+)? \+[0-9]+(,[0-9]+)? @@.*/ {
line=${BASH_REMATCH[2]} if ((x=index($3, ",")) > 0) {
elif [[ $REPLY =~ ^\+ ]]; then line=substr($3, 2, x-1)
flags="$flags:$line|green|+" } else {
((line++)) line=substr($3, 2)
elif [[ $REPLY =~ ^\- ]]; then }
flags="$flags:$line|red|-" }
fi /^\+/ {
done flags=flags ":" line "|green|+"
echo "set buffer git_diff_flags '$flags'" line++
} }
/^\-/ { flags=flags ":" line "|red|-" }
END { print "set buffer git_diff_flags ", flags }
'
} }
case "$1" in case "$1" in