define-command gitui -params .. %{ terminal-singleton git \ env "GIT_EDITOR=kak -c %val{session}" \ 'EDITOR=kcr edit' \ 'VISUAL=kcr edit' \ gitu %arg{@} } declare-user-mode git map global user g ': enter-user-mode git' -docstring 'Git mode' map global git s ': gitui' -docstring 'Git tui' map global git A ': git add %val{buffile}' -docstring 'Add file' map global git m ': git-line-blame' -docstring 'Blame selection lines' map global git M ': git-file-blame' -docstring 'Blame buffer file' map global git l ': git-link' -docstring 'Open remote link to selection in file' # diff declare-user-mode git-d map global git d ': enter-user-mode git-d' -docstring 'Diff mode' map global git-d d ': git-open-diff' -docstring 'Open staged files' map global git-d c ': git-open-commit' -docstring 'Open files changed in last commit' map global git-d x ': git-grep-conflict-markers' -docstring 'Find conflicts' map global git-d b ': git-diff-base-branch' -docstring 'Show diff against base branch' define-command git-grep-conflict-markers %{ grep <<<< } # rebase declare-user-mode git-r map global git r ': enter-user-mode git-r' -docstring 'Git re(base/set) mode' map global git-r f ': git reset HEAD^1 -- %val{buffile}' -docstring 'Split file out of last commit' # Hunk map global git n ': git next-hunk' -docstring 'Next hunk' map global git p ': git prev-hunk' -docstring 'Previous hunk' map global git h ': git-toggle-diff' -docstring 'Toggle hunk indicators' # Objects map global object m %{c^[=]{4\,}[^\n]*\n,^[=]{4\,}[^\n]*\n} -docstring 'conflict markers' set-option global git_diff_add_char "+" set-option global git_diff_del_char "-" set-option global git_diff_mod_char "~" set-option global git_diff_top_char "^" define-command git-toggle-diff %{ try %{ remove-highlighter window/git-diff } catch %{ git show-diff } catch %{ } } define-command git-line-blame %{ terminal-singleton git-blame sh -c \ "git -p log -u -L '%sh{echo ""$kak_selection_desc"" | sed -E 's/\.[0-9]+//g'}:%val{buffile}' --color=always | delta" } define-command git-file-blame %{ terminal-singleton git-blame gitu blame %val{buffile} } define-command git-open-diff -params 0..1 %{ eval %sh{ git diff --name-only "${1:-HEAD}" | sed 's/^/edit /' } } define-command git-open-commit -params 0..1 %{ eval %sh{ git show --name-only --pretty="" "$@" | sed 's/^/edit /' } } define-command git-diff-base-branch -params 0..1 %{ info %sh{ echo "origin/$("$kak_config/scripts/git.clj" base-branch)" } terminal-singleton git-diff git diff %sh{ echo "origin/$("$kak_config/scripts/git.clj" base-branch)" } } define-command git-link %{ eval %sh{ line_start=${kak_selection_desc%%.*} tmp=${kak_selection_desc#*,} line_end=${tmp%%.*} link=$("$kak_config/scripts/git.clj" link "$kak_buffile" "$line_start" "$line_end") xdg-open "$link" || true >/dev/null echo "info '$link'" } } # # 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 $hook .* 'git update-diff'\n" # done # fi # } # }