2013-04-17 19:15:15 +02:00
|
|
|
decl str docsclient
|
2013-03-29 19:37:35 +01:00
|
|
|
|
2013-04-22 19:35:22 +02:00
|
|
|
hook global WinSetOption filetype=git-log %{
|
|
|
|
addhl group git-log-highlight
|
|
|
|
addhl -group git-log-highlight regex '^(commit) ([0-9a-f]+)$' 1:yellow 2:red
|
|
|
|
addhl -group git-log-highlight regex '^([a-zA-Z_-]+:) (.*?)$' 1:green 2:magenta
|
|
|
|
}
|
2013-03-29 19:37:35 +01:00
|
|
|
|
2013-04-22 19:35:22 +02:00
|
|
|
hook global WinSetOption filetype=(?!git-log).* %{
|
|
|
|
rmhl git-log-highlight
|
|
|
|
}
|
2013-03-31 14:52:09 +02:00
|
|
|
|
|
|
|
decl line-flag-list git_blame_flags
|
2013-04-22 19:35:22 +02:00
|
|
|
decl line-flag-list git_diff_flags
|
|
|
|
|
|
|
|
def -shell-params git %{ %sh{
|
|
|
|
show_git_cmd_output() {
|
|
|
|
local filetype
|
|
|
|
case "$1" in
|
2013-04-25 18:52:06 +02:00
|
|
|
show|diff) filetype=diff ;;
|
2013-04-22 19:35:22 +02:00
|
|
|
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' %{"
|
2013-03-31 14:52:09 +02:00
|
|
|
|
2013-04-22 19:35:22 +02:00
|
|
|
echo "edit! -scratch *git*
|
|
|
|
exec |cat<space>${tmpfile}<ret>gk
|
|
|
|
nop %sh{rm ${tmpfile}}
|
2013-10-30 10:38:40 +01:00
|
|
|
set buffer filetype '${filetype}'"
|
2013-04-22 19:35:22 +02:00
|
|
|
|
|
|
|
[[ -n "$kak_opt_docsclient" ]] && echo "}"
|
|
|
|
else
|
|
|
|
echo "echo %{git $@ failed, see *debug* buffer}"
|
|
|
|
rm ${tmpfile}
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
run_git_blame() {
|
|
|
|
(
|
|
|
|
echo "eval -client '$kak_client' %{
|
2013-10-31 20:22:00 +01:00
|
|
|
try %{ addhl flag_lines magenta git_blame_flags }
|
2014-03-02 02:05:01 +01:00
|
|
|
set buffer=$kak_buffile git_blame_flags ''
|
2013-09-25 20:04:52 +02:00
|
|
|
}" | socat -u stdin UNIX-CONNECT:/tmp/kak-${kak_session}
|
2013-03-31 14:52:09 +02:00
|
|
|
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-07-26 01:53:11 +02:00
|
|
|
text=$(echo "${sha:0:8} ${dates[$sha]} ${authors[$sha]}" | sed -e 's/:/\\:/g')
|
2013-04-02 18:57:02 +02:00
|
|
|
flag="$line|black|$text"
|
2013-03-31 14:52:09 +02:00
|
|
|
for (( i=1; $i < $count; i++ )); do
|
2013-07-26 01:53:11 +02:00
|
|
|
flag="$flag:$(($line+$i))|black|$text"
|
2013-03-31 14:52:09 +02:00
|
|
|
done
|
2014-03-02 02:05:01 +01:00
|
|
|
echo "set -add buffer=$kak_buffile git_blame_flags %{${flag}}" | socat -u stdin UNIX-CONNECT:/tmp/kak-${kak_session}
|
2013-03-31 14:52:09 +02:00
|
|
|
}
|
2014-03-02 02:05:01 +01:00
|
|
|
git blame --incremental $kak_buffile | ( while read blame_line; do
|
2013-03-31 14:52:09 +02:00
|
|
|
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 )
|
2013-04-22 19:35:22 +02:00
|
|
|
) >& /dev/null < /dev/null &
|
|
|
|
}
|
2013-04-11 23:09:42 +02:00
|
|
|
|
2013-04-22 19:35:22 +02:00
|
|
|
update_diff() {
|
2014-03-02 02:05:01 +01:00
|
|
|
git diff -U0 $kak_buffile | {
|
2013-04-22 19:35:22 +02:00
|
|
|
local line=0
|
|
|
|
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
|
2013-07-26 01:53:11 +02:00
|
|
|
flags="$flags:$line|green|+"
|
2013-04-22 19:35:22 +02:00
|
|
|
((line++))
|
|
|
|
elif [[ $REPLY =~ ^\- ]]; then
|
2013-07-26 01:53:11 +02:00
|
|
|
flags="$flags:$line|red|-"
|
2013-04-22 19:35:22 +02:00
|
|
|
fi
|
|
|
|
done
|
2013-10-30 10:38:40 +01:00
|
|
|
echo "set buffer git_diff_flags '$flags'"
|
2013-04-22 19:35:22 +02:00
|
|
|
}
|
|
|
|
}
|
2013-04-17 19:15:15 +02:00
|
|
|
|
2013-04-22 19:35:22 +02:00
|
|
|
case "$1" in
|
2013-04-25 18:52:06 +02:00
|
|
|
show|log|diff) show_git_cmd_output "$@" ;;
|
2013-04-22 19:35:22 +02:00
|
|
|
blame) run_git_blame ;;
|
|
|
|
show-diff)
|
2013-10-31 20:22:00 +01:00
|
|
|
echo "try %{ addhl flag_lines black git_diff_flags }"
|
2013-04-22 19:35:22 +02:00
|
|
|
update_diff
|
|
|
|
;;
|
|
|
|
update-diff) update_diff ;;
|
2013-04-25 18:52:06 +02:00
|
|
|
add)
|
2014-03-02 02:05:01 +01:00
|
|
|
name="${2:-${kak_buffile}}"
|
2013-04-25 18:52:06 +02:00
|
|
|
if git add -- "${name}"; then
|
|
|
|
echo "echo -color Information 'git: added ${name}'"
|
|
|
|
else
|
|
|
|
echo "echo -color Error 'git: unable to add ${name}'"
|
|
|
|
fi
|
|
|
|
;;
|
2013-04-22 19:35:22 +02:00
|
|
|
*) echo "echo %{unknown git command '$1'}"; exit ;;
|
|
|
|
esac
|
2013-04-17 19:15:15 +02:00
|
|
|
|
2013-04-11 23:09:42 +02:00
|
|
|
}}
|