[[B]Commits] CTRL-Y to yank commit hashes to register

Close #516
This commit is contained in:
Junegunn Choi
2017-11-24 01:07:14 +09:00
parent ad113a64fc
commit 6902f6bc1c

View File

@@ -1043,16 +1043,29 @@ endfunction
" ------------------------------------------------------------------ " ------------------------------------------------------------------
" Commits / BCommits " Commits / BCommits
" ------------------------------------------------------------------ " ------------------------------------------------------------------
function! s:yank_to_register(data)
let @" = a:data
silent! let @* = a:data
silent! let @+ = a:data
endfunction
function! s:commits_sink(lines) function! s:commits_sink(lines)
if len(a:lines) < 2 if len(a:lines) < 2
return return
endif endif
let pat = '[0-9a-f]\{7,9}'
if a:lines[0] == 'ctrl-y'
let hashes = join(filter(map(a:lines[1:], 'matchstr(v:val, pat)'), 'len(v:val)'))
return s:yank_to_register(hashes)
end
let diff = a:lines[0] == 'ctrl-d' let diff = a:lines[0] == 'ctrl-d'
let cmd = s:action_for(a:lines[0], 'e') let cmd = s:action_for(a:lines[0], 'e')
let buf = bufnr('') let buf = bufnr('')
for idx in range(1, len(a:lines) - 1) for idx in range(1, len(a:lines) - 1)
let sha = matchstr(a:lines[idx], '[0-9a-f]\{7,9}') let sha = matchstr(a:lines[idx], pat)
if !empty(sha) if !empty(sha)
if diff if diff
if idx > 1 if idx > 1
@@ -1098,8 +1111,8 @@ function! s:commits(buffer_local, args)
\ 'sink*': s:function('s:commits_sink'), \ 'sink*': s:function('s:commits_sink'),
\ 'options': ['--ansi', '--multi', '--tiebreak=index', '--reverse', \ 'options': ['--ansi', '--multi', '--tiebreak=index', '--reverse',
\ '--inline-info', '--prompt', command.'> ', '--bind=ctrl-s:toggle-sort', \ '--inline-info', '--prompt', command.'> ', '--bind=ctrl-s:toggle-sort',
\ '--header', ':: Press '.s:magenta('CTRL-S', 'Special').' to toggle sort', \ '--header', ':: Press '.s:magenta('CTRL-S', 'Special').' to toggle sort, '.s:magenta('CTRL-Y', 'Special').' to yank commit hashes',
\ '--expect='.expect_keys] \ '--expect=ctrl-y,'.expect_keys]
\ } \ }
if a:buffer_local if a:buffer_local