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
|
|
|
|
2014-04-23 23:21:40 +02:00
|
|
|
hook global WinSetOption filetype=git-status %{
|
|
|
|
addhl group git-status-highlight
|
2015-03-31 00:06:46 +02:00
|
|
|
addhl -group git-status-highlight regex '^\h+(?:((?:both )?modified:)|(added:|new file:)|(deleted(?: by \w+)?:)|(renamed:)|(copied:))(?:.*?)$' 1:yellow 2:green 3:red 4:cyan 5:blue 6:magenta
|
2014-04-23 23:21:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
hook global WinSetOption filetype=(?!git-status).* %{
|
|
|
|
rmhl git-status-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
|
|
|
|
|
2014-04-23 23:21:40 +02:00
|
|
|
def -shell-params \
|
2015-01-15 20:58:43 +01:00
|
|
|
-docstring %sh{printf "%%{git wrapping helper\navailable commands:\n add\n blame\n commit\n checkout\n diff\n hide-blame\n log\n show\n show-diff\n status\n update-diff}"} \
|
2014-08-14 20:42:24 +02:00
|
|
|
-shell-completion %{
|
|
|
|
shift $(expr ${kak_token_to_complete})
|
|
|
|
prefix=${1:0:${kak_pos_in_token}}
|
|
|
|
(
|
2015-01-15 20:58:43 +01:00
|
|
|
for cmd in add blame commit checkout diff hide-blame log show show-diff status update-diff; do
|
2014-08-14 20:42:24 +02:00
|
|
|
expr "${cmd}" : "^\(${prefix}.*\)$"
|
|
|
|
done
|
|
|
|
) | grep -v '^$'
|
|
|
|
} \
|
2014-04-23 23:21:40 +02:00
|
|
|
git %{ %sh{
|
2013-04-22 19:35:22 +02:00
|
|
|
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 ;;
|
2014-04-23 23:21:40 +02:00
|
|
|
status) filetype=git-status ;;
|
2013-04-22 19:35:22 +02:00
|
|
|
esac
|
2014-05-06 20:39:24 +02: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}'
|
2015-02-20 19:43:09 +01:00
|
|
|
hook -group fifo buffer BufCloseFifo .* %{
|
|
|
|
nop %sh{ rm -r $(dirname ${output}) }
|
|
|
|
rmhooks buffer fifo
|
|
|
|
}
|
2014-05-06 20:39:24 +02:00
|
|
|
}"
|
2013-04-22 19:35:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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-25 10:25:37 +01:00
|
|
|
set buffer=$kak_bufname git_blame_flags ''
|
2014-03-02 03:05:38 +01:00
|
|
|
}" | kak -p ${kak_session}
|
2014-11-25 14:52:41 +01:00
|
|
|
git blame "$@" --incremental ${kak_buffile} | awk -e '
|
2014-03-25 10:25:37 +01:00
|
|
|
function send_flags(text, flag, i) {
|
|
|
|
if (line == "") { return; }
|
|
|
|
text=substr(sha,1,8) " " dates[sha] " " authors[sha]
|
|
|
|
gsub(":", "\\:", text)
|
2014-10-06 20:32:25 +02:00
|
|
|
gsub(",", "\\,", text)
|
|
|
|
flag=line ",black," text
|
2014-03-25 10:25:37 +01:00
|
|
|
for ( i=1; i < count; i++ ) {
|
2014-10-06 20:32:25 +02:00
|
|
|
flag=flag ":" line+i ",black," text
|
2014-03-25 10:25:37 +01:00
|
|
|
}
|
|
|
|
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 19:35:22 +02:00
|
|
|
}
|
2013-04-11 23:09:42 +02:00
|
|
|
|
2013-04-22 19:35:22 +02:00
|
|
|
update_diff() {
|
2014-03-25 10:25:37 +01:00
|
|
|
git diff -U0 $kak_buffile | awk -e '
|
|
|
|
BEGIN {
|
|
|
|
line=0
|
2014-10-06 20:32:25 +02:00
|
|
|
flags="0,red,."
|
2014-03-25 10:25:37 +01:00
|
|
|
}
|
|
|
|
/^---.*/ {}
|
|
|
|
/^@@ -[0-9]+(,[0-9]+)? \+[0-9]+(,[0-9]+)? @@.*/ {
|
|
|
|
if ((x=index($3, ",")) > 0) {
|
2015-01-22 22:18:59 +01:00
|
|
|
line=substr($3, 2, x-2)
|
2014-03-25 10:25:37 +01:00
|
|
|
} else {
|
|
|
|
line=substr($3, 2)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/^\+/ {
|
2014-10-06 20:32:25 +02:00
|
|
|
flags=flags ":" line ",green,+"
|
2014-03-25 10:25:37 +01:00
|
|
|
line++
|
|
|
|
}
|
2014-10-06 20:32:25 +02:00
|
|
|
/^\-/ { flags=flags ":" line ",red,-" }
|
2014-03-25 10:25:37 +01:00
|
|
|
END { print "set buffer git_diff_flags ", flags }
|
|
|
|
'
|
2013-04-22 19:35:22 +02:00
|
|
|
}
|
2013-04-17 19:15:15 +02:00
|
|
|
|
2015-01-15 20:58:43 +01:00
|
|
|
commit() {
|
2015-01-21 14:43:00 +01:00
|
|
|
# Handle case where message needs not to be edited
|
|
|
|
if grep -E -q -e "-m|-F|-C|--message=.*|--file=.*|--reuse-message=.*|--no-edit"; then
|
|
|
|
if git commit "$@" > /dev/null 2>&1; then
|
|
|
|
echo 'echo -color Information Commit succeeded'
|
|
|
|
else
|
|
|
|
echo 'echo -color Error Commit failed'
|
|
|
|
fi
|
|
|
|
exit
|
|
|
|
fi <<-EOF
|
|
|
|
$@
|
|
|
|
EOF
|
|
|
|
|
2015-01-15 20:58:43 +01:00
|
|
|
# fails, and generate COMMIT_EDITMSG
|
|
|
|
GIT_EDITOR='' EDITOR='' git commit > /dev/null 2>&1
|
|
|
|
msgfile="$(git rev-parse --git-dir)/COMMIT_EDITMSG"
|
|
|
|
echo "edit '$msgfile'
|
|
|
|
hook buffer BufWritePost '.*\Q$msgfile\E' %{ %sh{
|
|
|
|
if git commit -F '$msgfile' --cleanup=strip $@ > /dev/null; then
|
|
|
|
echo 'eval -client $kak_client echo -color Information Commit succeeded'
|
|
|
|
echo 'delbuf'
|
|
|
|
else
|
|
|
|
echo 'eval -client $kak_client echo -color Error Commit failed'
|
|
|
|
fi
|
|
|
|
} }"
|
|
|
|
}
|
|
|
|
|
2013-04-22 19:35:22 +02:00
|
|
|
case "$1" in
|
2014-04-23 23:21:40 +02:00
|
|
|
show|log|diff|status) show_git_cmd_output "$@" ;;
|
2014-11-25 14:52:41 +01:00
|
|
|
blame) shift; run_git_blame "$@" ;;
|
2015-05-10 18:20:42 +02:00
|
|
|
hide-blame)
|
|
|
|
echo "try %{
|
|
|
|
set buffer=$kak_bufname git_blame_flags ''
|
|
|
|
rmhl hlflags_git_blame_flags
|
|
|
|
}"
|
|
|
|
;;
|
2013-04-22 19:35:22 +02:00
|
|
|
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 ;;
|
2015-01-15 20:58:43 +01:00
|
|
|
commit) shift; commit "$@" ;;
|
2014-04-23 23:21:40 +02:00
|
|
|
checkout)
|
|
|
|
name="${2:-${kak_buffile}}"
|
|
|
|
git checkout "${name}"
|
|
|
|
;;
|
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
|
|
|
|
;;
|
2014-04-23 23:21:40 +02:00
|
|
|
*) echo "echo -color Error %{unknown git command '$1'}"; exit ;;
|
2013-04-22 19:35:22 +02:00
|
|
|
esac
|
2013-04-11 23:09:42 +02:00
|
|
|
}}
|