Enable git update-diff automatically


Could someone help me configuring Kakoune to automatically run git show-diff and git update-diff on file opening and updates? I tried with

hook global BufOpenFile .* %{ git show-diff }
hook global BufWritePost .* %{ git update-diff }

but without success. Probably I didn’t understand how to use hooks yet…


hook global WinCreate .* %{ git show-diff }

My suspicion is that BufOpenFile is triggered when the file is opened but before it is displayed. Additionally git show-dif sets the highlighter at the window level anyway so you would need to activate for each window regardless. In Kakoune a window is a view into a buffer.

I have following setup:

# enable flag-lines hl for git diff
hook global WinCreate .* %{
    add-highlighter window/git-diff flag-lines Default git_diff_flags
# trigger update diff if inside git dir
hook global BufOpenFile .* %{
    evaluate-commands -draft %sh{
        cd $(dirname "$kak_buffile")
        if [ $(git rev-parse --git-dir 2>/dev/null) ]; then
            for hook in WinCreate BufReload BufWritePost; do
                printf "hook buffer -group git-update-diff %s .* 'git update-diff'\n" "$hook"

That worked! Thank you both!