Skip to content

Instantly share code, notes, and snippets.

@bfrg
Last active August 10, 2020 20:55
Show Gist options
  • Save bfrg/2311124ed4511f69e94903b3e1986f04 to your computer and use it in GitHub Desktop.
Save bfrg/2311124ed4511f69e94903b3e1986f04 to your computer and use it in GitHub Desktop.
Vanilla git-blame
" 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