[BCommits] Add BCommits command
This commit is contained in:
parent
5c25913b25
commit
921d92ff4a
4 changed files with 31 additions and 5 deletions
|
@ -64,6 +64,7 @@ Commands
|
|||
| `History/` | Search history |
|
||||
| `Snippets` | Snippets ([UltiSnips][us]) |
|
||||
| `Commits` | Git commits (requires [fugitive.vim][f]) |
|
||||
| `BCommits` | Git commits for the current buffer |
|
||||
| `Commands` | Commands |
|
||||
| `Helptags` | Help tags <sup id="a1">[1](#helptags)</sup> |
|
||||
|
||||
|
|
|
@ -615,7 +615,7 @@ function! fzf#vim#windows(...)
|
|||
endfunction
|
||||
|
||||
" ------------------------------------------------------------------
|
||||
" Commits
|
||||
" Commits / BCommits
|
||||
" ------------------------------------------------------------------
|
||||
function! s:commits_sink(lines)
|
||||
if len(a:lines) < 2
|
||||
|
@ -641,20 +641,35 @@ function! s:commits_sink(lines)
|
|||
endfor
|
||||
endfunction
|
||||
|
||||
function! fzf#vim#commits(...)
|
||||
function! s:commits(buffer_local, args)
|
||||
let s:git_root = s:chomp(system('git rev-parse --show-toplevel'))
|
||||
if v:shell_error
|
||||
call s:warn('Not in git repository')
|
||||
return
|
||||
endif
|
||||
|
||||
let source = 'git log --graph --color=always --format="%C(auto)%h%d %s %C(black)%C(bold)%cr"'
|
||||
let current = expand('%:S')
|
||||
let managed = 0
|
||||
if !empty(current)
|
||||
call system('git show '.current.' 2> /dev/null')
|
||||
let managed = !v:shell_error
|
||||
endif
|
||||
|
||||
if a:buffer_local
|
||||
if !managed
|
||||
call s:warn('The current buffer is not in the working tree')
|
||||
return
|
||||
endif
|
||||
let source .= ' --follow '.current
|
||||
endif
|
||||
|
||||
let options = {
|
||||
\ 'source': 'git log --graph --color=always --format="%C(auto)%h%d %s %C(black)%C(bold)%cr"',
|
||||
\ 'source': source,
|
||||
\ 'sink*': function('s:commits_sink'),
|
||||
\ 'options': '--ansi --multi --no-sort --reverse --inline-info --prompt "Commits> "'.s:expect()
|
||||
\ }
|
||||
|
||||
let current = expand('%:S')
|
||||
if !empty(current)
|
||||
call system('git show '.current)
|
||||
if !v:shell_error
|
||||
|
@ -662,7 +677,15 @@ function! fzf#vim#commits(...)
|
|||
endif
|
||||
endif
|
||||
|
||||
call s:fzf(options, a:000)
|
||||
call s:fzf(options, a:args)
|
||||
endfunction
|
||||
|
||||
function! fzf#vim#commits(...)
|
||||
return s:commits(0, a:000)
|
||||
endfunction
|
||||
|
||||
function! fzf#vim#buffer_commits(...)
|
||||
return s:commits(1, a:000)
|
||||
endfunction
|
||||
|
||||
" ----------------------------------------------------------------------------
|
||||
|
|
|
@ -90,6 +90,7 @@ COMMANDS *fzf-vim-commands*
|
|||
`History/` | Search history
|
||||
`Snippets` | Snippets ({UltiSnips}{6})
|
||||
`Commits` | Git commits (requires {fugitive.vim}{7})
|
||||
`BCommits` | Git commits for the current buffer
|
||||
`Commands` | Commands
|
||||
`Helptags` | Help tags [1]
|
||||
-----------------+---------------------------------------------------------------------
|
||||
|
|
|
@ -45,6 +45,7 @@ command! -bang Marks call fzf#vim#marks(s:w(<bang>0))
|
|||
command! -bang Helptags call fzf#vim#helptags(s:w(<bang>0))
|
||||
command! -bang Windows call fzf#vim#windows(s:w(<bang>0))
|
||||
command! -bang Commits call fzf#vim#commits(s:w(<bang>0))
|
||||
command! -bang BCommits call fzf#vim#buffer_commits(s:w(<bang>0))
|
||||
|
||||
function! s:history(arg, bang)
|
||||
let bang = a:bang || a:arg[len(a:arg)-1] == '!'
|
||||
|
|
Loading…
Add table
Reference in a new issue