declare-user-mode git map -docstring "git" global user g ": enter-user-mode git" map -docstring "lazygit kak cwd" global git g ": terminal lazygit" define-command lazygit-buffer-dir %{ evaluate-commands %sh{ ROOT="$(env -C "$(dirname $kak_buffile)" git rev-parse --show-toplevel)" printf "terminal lazygit -p %s" "$ROOT" } } map -docstring "lazygit buffer directory" global git G ": lazygit-buffer-dir" define-command git-blame %{ info %sh{ git -C $(dirname $(realpath $kak_buffile)) blame -L $kak_cursor_line,$kak_cursor_line $(realpath $kak_buffile) } } map -docstring "blame" global git b ": git-blame" map -docstring "show diff" global git d ": git show-diff" map -docstring "hide diff" global git D ": git hide-diff" provide-module git-diff %~ define-command -hidden git-show-diff %{ evaluate-commands %sh{ if [ $kak_buffile != $kak_bufname ] && git ls-files --error-unmatch "$kak_buffile" > /dev/null 2>&1; then echo "git show-diff" fi } } hook global WinCreate .* %{ evaluate-commands %sh{ if [ $kak_buffile != $kak_bufname ] && git ls-files --error-unmatch "$kak_buffile" > /dev/null 2>&1; then echo "hook window BufWritePost .* git-show-diff" echo "hook window BufReload .* git-show-diff" fi } } hook global WinCreate .* %{ evaluate-commands %sh{ if [ $kak_buffile != $kak_bufname ] && git ls-files --error-unmatch "$kak_buffile" > /dev/null 2>&1; then echo "git show-diff" fi } } ~