2013-04-17 21:15:15 +04:00
|
|
|
decl str docsclient
|
2013-03-29 22:37:35 +04:00
|
|
|
|
2013-04-22 21:35:22 +04: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 22:37:35 +04:00
|
|
|
|
2013-04-22 21:35:22 +04:00
|
|
|
hook global WinSetOption filetype=(?!git-log).* %{
|
|
|
|
rmhl git-log-highlight
|
|
|
|
}
|
2013-03-31 16:52:09 +04:00
|
|
|
|
2014-04-24 01:21:40 +04:00
|
|
|
hook global WinSetOption filetype=git-status %{
|
|
|
|
addhl group git-status-highlight
|
|
|
|
addhl -group git-status-highlight regex '^#\h+((modified:)|(added:)|(deleted:)|(renamed:)|(copied:))(.*?)$' 2:yellow 3:green 4:red 5:cyan 6:blue 7:magenta
|
|
|
|
}
|
|
|
|
|
|
|
|
hook global WinSetOption filetype=(?!git-status).* %{
|
|
|
|
rmhl git-status-highlight
|
|
|
|
}
|
|
|
|
|
2013-03-31 16:52:09 +04:00
|
|
|
decl line-flag-list git_blame_flags
|
2013-04-22 21:35:22 +04:00
|
|
|
decl line-flag-list git_diff_flags
|
|
|
|
|
2014-04-24 01:21:40 +04:00
|
|
|
def -shell-params \
|
|
|
|
-docstring "git wrapping helper" \
|
|
|
|
git %{ %sh{
|
2013-04-22 21:35:22 +04:00
|
|
|
show_git_cmd_output() {
|
|
|
|
local filetype
|
|
|
|
case "$1" in
|
2013-04-25 20:52:06 +04:00
|
|
|
show|diff) filetype=diff ;;
|
2013-04-22 21:35:22 +04:00
|
|
|
log) filetype=git-log ;;
|
2014-04-24 01:21:40 +04:00
|
|
|
status) filetype=git-status ;;
|
2013-04-22 21:35:22 +04:00
|
|
|
esac
|
2014-05-06 22:39:24 +04:00
|
|
|
output=$(mktemp -d -t kak-git.XXXXXXXX)/fifo
|
|
|
|
mkfifo ${output}
|
|
|
|
( git "$@" > ${output} 2>&1 ) > /dev/null 2>&1 < /dev/null &
|
|
|
|
|
|
|
|
echo "eval -try-client '$kak_opt_docsclient' %{
|
|
|
|
edit! -fifo ${output} *git*
|
|
|
|
set buffer filetype '${filetype}'
|
2014-06-16 22:49:58 +04:00
|
|
|
hook buffer BufCloseFifo .* %{ nop %sh{ rm -r $(dirname ${output}) } }
|
2014-05-06 22:39:24 +04:00
|
|
|
}"
|
2013-04-22 21:35:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
run_git_blame() {
|
|
|
|
(
|
|
|
|
echo "eval -client '$kak_client' %{
|
2013-10-31 23:22:00 +04:00
|
|
|
try %{ addhl flag_lines magenta git_blame_flags }
|
2014-03-25 13:25:37 +04:00
|
|
|
set buffer=$kak_bufname git_blame_flags ''
|
2014-03-02 06:05:38 +04:00
|
|
|
}" | kak -p ${kak_session}
|
2014-03-25 13:25:37 +04:00
|
|
|
git blame --incremental ${kak_buffile} | awk -e '
|
|
|
|
function send_flags(text, flag, i) {
|
|
|
|
if (line == "") { return; }
|
|
|
|
text=substr(sha,1,8) " " dates[sha] " " authors[sha]
|
|
|
|
gsub(":", "\\:", text)
|
|
|
|
flag=line "|black|" text
|
|
|
|
for ( i=1; i < count; i++ ) {
|
|
|
|
flag=flag ":" line+i "|black|" text
|
|
|
|
}
|
|
|
|
cmd = "kak -p " ENVIRON["kak_session"]
|
|
|
|
print "set -add buffer=" ENVIRON["kak_bufname"] " git_blame_flags %{" flag "}" | cmd
|
|
|
|
close(cmd)
|
|
|
|
}
|
|
|
|
/^([0-9a-f]{40}) ([0-9]+) ([0-9]+) ([0-9]+)/ {
|
|
|
|
send_flags()
|
|
|
|
sha=$1
|
|
|
|
line=$3
|
|
|
|
count=$4
|
|
|
|
}
|
|
|
|
/^author / { authors[sha]=substr($0,8) }
|
|
|
|
/^author-time ([0-9]*)/ {
|
|
|
|
cmd = "date -d @" $2 " +\"%F %T\""
|
|
|
|
cmd | getline dates[sha]
|
|
|
|
}
|
|
|
|
END { send_flags(); }'
|
|
|
|
) > /dev/null 2>&1 < /dev/null &
|
2013-04-22 21:35:22 +04:00
|
|
|
}
|
2013-04-12 01:09:42 +04:00
|
|
|
|
2013-04-22 21:35:22 +04:00
|
|
|
update_diff() {
|
2014-03-25 13:25:37 +04:00
|
|
|
git diff -U0 $kak_buffile | awk -e '
|
|
|
|
BEGIN {
|
|
|
|
line=0
|
|
|
|
flags="0|red|."
|
|
|
|
}
|
|
|
|
/^---.*/ {}
|
|
|
|
/^@@ -[0-9]+(,[0-9]+)? \+[0-9]+(,[0-9]+)? @@.*/ {
|
|
|
|
if ((x=index($3, ",")) > 0) {
|
|
|
|
line=substr($3, 2, x-1)
|
|
|
|
} else {
|
|
|
|
line=substr($3, 2)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/^\+/ {
|
|
|
|
flags=flags ":" line "|green|+"
|
|
|
|
line++
|
|
|
|
}
|
|
|
|
/^\-/ { flags=flags ":" line "|red|-" }
|
|
|
|
END { print "set buffer git_diff_flags ", flags }
|
|
|
|
'
|
2013-04-22 21:35:22 +04:00
|
|
|
}
|
2013-04-17 21:15:15 +04:00
|
|
|
|
2013-04-22 21:35:22 +04:00
|
|
|
case "$1" in
|
2014-04-24 01:21:40 +04:00
|
|
|
show|log|diff|status) show_git_cmd_output "$@" ;;
|
2013-04-22 21:35:22 +04:00
|
|
|
blame) run_git_blame ;;
|
2014-05-09 16:51:15 +04:00
|
|
|
hide-blame) echo "try %{ rmhl hlflags_git_blame_flags }" ;;
|
2013-04-22 21:35:22 +04:00
|
|
|
show-diff)
|
2013-10-31 23:22:00 +04:00
|
|
|
echo "try %{ addhl flag_lines black git_diff_flags }"
|
2013-04-22 21:35:22 +04:00
|
|
|
update_diff
|
|
|
|
;;
|
|
|
|
update-diff) update_diff ;;
|
2014-04-24 01:21:40 +04:00
|
|
|
checkout)
|
|
|
|
name="${2:-${kak_buffile}}"
|
|
|
|
git checkout "${name}"
|
|
|
|
;;
|
2013-04-25 20:52:06 +04:00
|
|
|
add)
|
2014-03-02 05:05:01 +04:00
|
|
|
name="${2:-${kak_buffile}}"
|
2013-04-25 20:52:06 +04:00
|
|
|
if git add -- "${name}"; then
|
|
|
|
echo "echo -color Information 'git: added ${name}'"
|
|
|
|
else
|
|
|
|
echo "echo -color Error 'git: unable to add ${name}'"
|
|
|
|
fi
|
|
|
|
;;
|
2014-04-24 01:21:40 +04:00
|
|
|
*) echo "echo -color Error %{unknown git command '$1'}"; exit ;;
|
2013-04-22 21:35:22 +04:00
|
|
|
esac
|
2013-04-12 01:09:42 +04:00
|
|
|
}}
|