From c01fecb8b2af400aa1240692a6106e1a16836702 Mon Sep 17 00:00:00 2001 From: DarkWiiPlayer Date: Tue, 21 May 2019 08:38:28 +0200 Subject: [PATCH] Redo Blame command for vim --- git.vim | 64 ++++++++++++++++++++++----------------------------------- 1 file changed, 25 insertions(+), 39 deletions(-) diff --git a/git.vim b/git.vim index 9ba8e4e..d8bfb09 100644 --- a/git.vim +++ b/git.vim @@ -1,10 +1,11 @@ -" ┌─────────────────┐ " -" └─┬─┬───┬─┬───┬─┬─┘ " -" │ │ │ │ │ │ " -" │ │ │ │ │ │ " -" ┌─┴─┴───┴─┴───┴─┴─┐ " -" ┌┘ Git Stuff └┐ " -" └───────────────────┘ " +" vim: set noexpandtab :miv " +" ┌─────────────────┐ " +" └─┬─┬───┬─┬───┬─┬─┘ " +" │ │ │ │ │ │ " +" │ │ │ │ │ │ " +" ┌─┴─┴───┴─┴───┴─┴─┐ " +" ┌┘ Git Stuff └┐ " +" └───────────────────┘ " " Find the root of a git repository function! s:gitroot() @@ -164,46 +165,31 @@ function! s:git_diff(...) end endfun -function! s:git_blame() - let l:name = expand('%') - let l:line = getpos('.')[1] - let l:char = getpos('.')[2]+59 - let l:type = &filetype - enew - set modifiable - let &filetype = l:type - set buftype=nofile - set bufhidden=delete - set nowrap - silent exec "file Blame: ".l:name - keepjumps exec 'r !git blame '.l:name - keepjumps 0,0del " - set nomodifiable - keepjumps call setpos('.', [0, l:line, l:char, 0]) +function! s:git_blame(first, last) + let l:input = system('git blame '.expand('%').' --line-porcelain -L '.a:first.','.a:last) + let l:data = map(split(l:input, '\ze\x\{40} \d\+ \d\+'), {idx, elem -> split(elem, '\n')}) + return map(l:data, {idx, ary -> ary[1][match(ary[1], '\s\+\zs'):]}) endfun -command! Blame try - \| call s:gitroot() | call git_blame() - \| catch | echo 'Not a git repo!' - \| endtry +command! -range Blame echom join(uniq(sort(git_blame(, ))), ', ') command! GitNext try - \| call s:gitroot() | call git_next() | call s:git_info() - \| catch | echo 'Not a git repo!' - \| endtry + \| call s:gitroot() | call git_next() | call s:git_info() + \| catch | echo 'Not a git repo!' + \| endtry command! GitPrev call git_prev() | call s:git_info() command! GitFirst call git_first() | call s:git_info() command! GitLast call git_last() | call s:git_info() command! GitInfo call git_info() command! -nargs=1 GitCheckout call file_at_revision() command! -nargs=? GitCompare try - \| call s:gitroot() | call git_diff() - \| catch | echo 'Not a git repo!' - \| endtry + \| call s:gitroot() | call git_diff() + \| catch | echo 'Not a git repo!' + \| endtry command! Uncommited try - \| call s:gitroot() | call git_diff() - \| catch | echo 'Not a git repo!' - \| endtry + \| call s:gitroot() | call git_diff() + \| catch | echo 'Not a git repo!' + \| endtry command! GitRoot try - \| echo gitroot() - \| catch | echo 'Not a git repository' - \| endtry + \| echo gitroot() + \| catch | echo 'Not a git repository' + \| endtry