-
Notifications
You must be signed in to change notification settings - Fork 0
/
.vimrc.gitlogviewer
61 lines (53 loc) · 1.79 KB
/
.vimrc.gitlogviewer
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
" refer from : https://gist.github.com/deris/5548058/raw/7e753c7eda604c86e2a9ae19aa7530046ab2dd11/gitlogviewer.vim
"
" Inspired by ujihisa's vimrc
function! s:GitLogViewer()
" vnewだとコミットメッセージが切れてしまうのでnew
new
VimProcRead git log -u 'HEAD~30..HEAD'
set filetype=git-log.git-diff
setlocal foldmethod=expr
setlocal foldexpr=getline(v:lnum)=~'^commit'?'>1':getline(v:lnum+1)=~'^commit'?'<1':'='
setlocal foldtext=FoldTextOfGitLog()
endfunction
command! GitLogViewer call s:GitLogViewer()
" git log表示時の折りたたみ用
function! FoldTextOfGitLog()
let month_map = {
\ 'Jan' : '01',
\ 'Feb' : '02',
\ 'Mar' : '03',
\ 'Apr' : '04',
\ 'May' : '05',
\ 'Jun' : '06',
\ 'Jul' : '07',
\ 'Aug' : '08',
\ 'Sep' : '09',
\ 'Oct' : '10',
\ 'Nov' : '11',
\ 'Dec' : '12',
\ }
if getline(v:foldstart) !~ '^commit'
return getline(v:foldstart)
endif
if getline(v:foldstart + 1) =~ '^Author:'
let author_lnum = v:foldstart + 1
elseif getline(v:foldstart + 2) =~ '^Author:'
" commitの次の行がMerge:の場合があるので
let author_lnum = v:foldstart + 2
else
" commitの下2行がどちらもAuthor:で始まらなければ諦めて終了
return getline(v:foldstart)
endif
let date_lnum = author_lnum + 1
let message_lnum = date_lnum + 2
let author = matchstr(getline(author_lnum), '^Author: \zs.*\ze <.\{-}>')
let date = matchlist(getline(date_lnum), ' \(\a\{3}\) \(\d\{1,2}\) \(\d\{2}:\d\{2}:\d\{2}\) \(\d\{4}\)')
let message = getline(message_lnum)
let month = date[1]
let day = printf('%02s', date[2])
let time = date[3]
let year = date[4]
let datestr = join([year, month_map[month], day], '-')
return join([datestr, time, author, message], ' ')
endfunction