/usr/share/kak/rc/extra/git-tools.kak is in kakoune 0~2016.12.20.1.3a6167ae-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | decl str docsclient
hook -group git-log-highlight 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
addhl -group git-log-highlight ref diff # highlight potential diffs from the -p option
}
hook -group git-log-highlight global WinSetOption filetype=(?!git-log).* %{ rmhl git-log-highlight }
hook -group git-status-highlight global WinSetOption filetype=git-status %{
addhl group git-status-highlight
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
}
hook -group git-status-highlight global WinSetOption filetype=(?!git-status).* %{ rmhl git-status-highlight }
decl line-flags git_blame_flags
decl line-flags git_diff_flags
face GitBlame default,magenta
face GitDiffFlags default,black
def -params 1.. \
-docstring %sh{printf '%%{git [<arguments>]: git wrapping helper
All the optional arguments are forwarded to the git utility
Available commands:\n-add\n-rm\n-blame\n-commit\n-checkout\n-diff\n-hide-blame\n-log\n-show\n-show-diff\n-status\n-update-diff}'} \
-shell-candidates %{
[ $kak_token_to_complete -eq 0 ] &&
printf "add\nrm\nblame\ncommit\ncheckout\ndiff\nhide-blame\nlog\nshow\nshow-diff\nstatus\nupdate-diff\n"
} \
git %{ %sh{
show_git_cmd_output() {
local filetype
case "$1" in
show|diff) filetype=diff ;;
log) filetype=git-log ;;
status) filetype=git-status ;;
esac
output=$(mktemp -d -t kak-git.XXXXXXXX)/fifo
mkfifo ${output}
( git "$@" > ${output} 2>&1 ) > /dev/null 2>&1 < /dev/null &
printf %s "eval -try-client '$kak_opt_docsclient' %{
edit! -fifo ${output} *git*
set buffer filetype '${filetype}'
hook -group fifo buffer BufCloseFifo .* %{
nop %sh{ rm -r $(dirname ${output}) }
rmhooks buffer fifo
}
}"
}
run_git_blame() {
(
printf %s "eval -client '$kak_client' %{
try %{ addhl flag_lines GitBlame git_blame_flags }
set buffer=$kak_bufname git_blame_flags '$kak_timestamp'
}" | kak -p ${kak_session}
git blame "$@" --incremental ${kak_buffile} | awk '
function send_flags(text, flag, i) {
if (line == "") { return; }
text=substr(sha,1,8) " " dates[sha] " " authors[sha]
gsub(":", "\\:", text)
# gsub("|", "\\|", text)
flag=line "|" text
for ( i=1; i < count; i++ ) {
flag=flag ":" line+i "|" 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 &
}
update_diff() {
git diff -U0 $kak_buffile | awk '
BEGIN {
line=0
flags=ENVIRON["kak_timestamp"]
}
/^---.*/ {}
/^@@ -[0-9]+(,[0-9]+)? \+[0-9]+(,[0-9]+)? @@.*/ {
if ((x=index($3, ",")) > 0) {
line=substr($3, 2, x-2)
} else {
line=substr($3, 2)
}
}
/^\+/ {
flags=flags ":" line "|{green}+"
line++
}
/^\-/ { flags=flags ":" line "|{red}-" }
END { print "set buffer git_diff_flags ", flags }
'
}
commit() {
# 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
# fails, and generate COMMIT_EDITMSG
GIT_EDITOR='' EDITOR='' git commit "$@" > /dev/null 2>&1
msgfile="$(git rev-parse --git-dir)/COMMIT_EDITMSG"
printf %s "edit '$msgfile'
hook buffer BufWritePost '.*\Q$msgfile\E' %{ %sh{
if git commit -F '$msgfile' --cleanup=strip $@ > /dev/null; then
printf %s 'eval -client $kak_client echo -color Information Commit succeeded; delete-buffer'
else
printf %s 'eval -client $kak_client echo -color Error Commit failed'
fi
} }"
}
case "$1" in
show|log|diff|status) show_git_cmd_output "$@" ;;
blame) shift; run_git_blame "$@" ;;
hide-blame)
printf %s "try %{
set buffer=$kak_bufname git_blame_flags ''
rmhl hlflags_git_blame_flags
}"
;;
show-diff)
echo 'try %{ addhl flag_lines GitDiffFlags git_diff_flags }'
update_diff
;;
update-diff) update_diff ;;
commit) shift; commit "$@" ;;
checkout)
name="${2:-${kak_buffile}}"
git checkout "${name}" > /dev/null 2>&1
;;
add)
name="${2:-${kak_buffile}}"
if git add -- "${name}" > /dev/null 2>&1; then
printf %s "echo -color Information 'git: added ${name}'"
else
printf %s "echo -color Error 'git: unable to add ${name}'"
fi
;;
rm)
name="${2:-${kak_buffile}}"
if git rm -- "${name}" > /dev/null 2>&1; then
printf %s "echo -color Information 'git: removed ${name}'"
else
printf %s "echo -color Error 'git: unable to remove ${name}'"
fi
;;
*) printf %s "echo -color Error %{unknown git command '$1'}"; exit ;;
esac
}}
|