Last active
August 10, 2020 20:55
-
-
Save bfrg/2311124ed4511f69e94903b3e1986f04 to your computer and use it in GitHub Desktop.
Vanilla git-blame
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Vanilla git-blame | |
" | |
" git-blame current line: | |
" :GB | |
" | |
" git-blame selected lines: | |
" :'<,'>GB | |
" | |
" git-blame entire buffer: | |
" :%GB | |
function s:git_blame(line1, line2) abort | |
let cmd = printf('git -C %s blame -L %d,%d %s', expand('%:p:h')->shellescape(), a:line1, a:line2, expand('%:t')) | |
let git = systemlist(cmd) | |
call map(git, {_, i -> printf('git -C %s log -1 --date=relative --pretty=format:"%%an, %%cd • %%s" %s', | |
\ expand('%:p:h'), | |
\ matchstr(i, '^\^\=\zs[a-z0-9]\+') | |
\ )->systemlist()[0] | |
\ }) | |
echo join(git, "\n") | |
endfunction | |
command -range GB call s:git_blame(<line1>, <line2>) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment