declare-option str awk_cmd 'awk' declare-user-mode git map global git ':git-show-current-line' -docstring 'open last commit that touched current line' map global git b ':git-branches' -docstring 'list branches' map global git B ':git-blame-current-line' -docstring 'blame current line' map global git n ':git next-hunk' -docstring 'goto next hunk' map global git p ':git prev-hunk' -docstring 'goto previous hunk' map global git d ':git diff' -docstring 'diff' ## Blame current line set-face global GitBlameLineRef red,black set-face global GitBlameLineSummary green,black set-face global GitBlameLineAuthor blue,black set-face global GitBlameLineTime default,black@comment define-command git-blame-current-line %{ info -markup -style above -anchor "%val{cursor_line}.%val{cursor_column}" -- %sh{ git blame -L$kak_cursor_line,$kak_cursor_line $kak_bufname --incremental | $kak_opt_awk_cmd '\ BEGIN { ref = "" author = "" time = "" summary = "" } /^[a-f0-9]+ [0-9]+ [0-9]+ [0-9]+$/ { ref = substr($1, 0, 8) } /summary/ { for (i = 2; i < NF; i++) { summary = summary $i " " } summary = summary $NF } /author / { for (i = 2; i < NF; i++) { author = author $i " " } author = author $NF } /author-time/ { time = strftime("%a %d %b %Y, %H:%M:%S", $2) } END { first = sprintf("{GitBlameLineRef}%s {GitBlameLineSummary}%s", ref, summary) second = sprintf("{GitBlameLineAuthor}%s {GitBlameLineTime}on %s", author, time) max_len = length(first) second_len = length(second) if (second_len > max_len) { max_len = second_len } fmt_string = sprintf("%%-%ds", max_len) printf fmt_string "\n", first printf fmt_string, second }' } } ## Show the commit that touched the line under the cursor. declare-option str git_show_current_line_commit define-command git-show-current-line %{ set-option global git_show_current_line_commit %sh{ git blame -L$kak_cursor_line,$kak_cursor_line $kak_bufname | cut -d' ' -f1 } edit -scratch *git* set-option buffer filetype git-commit execute-keys '%|git show --pretty=fuller $kak_opt_git_show_current_line_commitgg' set-option buffer readonly true }