mirror of
https://github.com/junegunn/fzf.vim.git
synced 2025-12-08 05:24:47 +08:00
[BCommits] Add BCommits command
This commit is contained in:
@@ -64,6 +64,7 @@ Commands
|
|||||||
| `History/` | Search history |
|
| `History/` | Search history |
|
||||||
| `Snippets` | Snippets ([UltiSnips][us]) |
|
| `Snippets` | Snippets ([UltiSnips][us]) |
|
||||||
| `Commits` | Git commits (requires [fugitive.vim][f]) |
|
| `Commits` | Git commits (requires [fugitive.vim][f]) |
|
||||||
|
| `BCommits` | Git commits for the current buffer |
|
||||||
| `Commands` | Commands |
|
| `Commands` | Commands |
|
||||||
| `Helptags` | Help tags <sup id="a1">[1](#helptags)</sup> |
|
| `Helptags` | Help tags <sup id="a1">[1](#helptags)</sup> |
|
||||||
|
|
||||||
|
|||||||
@@ -615,7 +615,7 @@ function! fzf#vim#windows(...)
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" ------------------------------------------------------------------
|
" ------------------------------------------------------------------
|
||||||
" Commits
|
" Commits / BCommits
|
||||||
" ------------------------------------------------------------------
|
" ------------------------------------------------------------------
|
||||||
function! s:commits_sink(lines)
|
function! s:commits_sink(lines)
|
||||||
if len(a:lines) < 2
|
if len(a:lines) < 2
|
||||||
@@ -641,20 +641,35 @@ function! s:commits_sink(lines)
|
|||||||
endfor
|
endfor
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! fzf#vim#commits(...)
|
function! s:commits(buffer_local, args)
|
||||||
let s:git_root = s:chomp(system('git rev-parse --show-toplevel'))
|
let s:git_root = s:chomp(system('git rev-parse --show-toplevel'))
|
||||||
if v:shell_error
|
if v:shell_error
|
||||||
call s:warn('Not in git repository')
|
call s:warn('Not in git repository')
|
||||||
return
|
return
|
||||||
endif
|
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 = {
|
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'),
|
\ 'sink*': function('s:commits_sink'),
|
||||||
\ 'options': '--ansi --multi --no-sort --reverse --inline-info --prompt "Commits> "'.s:expect()
|
\ 'options': '--ansi --multi --no-sort --reverse --inline-info --prompt "Commits> "'.s:expect()
|
||||||
\ }
|
\ }
|
||||||
|
|
||||||
let current = expand('%:S')
|
|
||||||
if !empty(current)
|
if !empty(current)
|
||||||
call system('git show '.current)
|
call system('git show '.current)
|
||||||
if !v:shell_error
|
if !v:shell_error
|
||||||
@@ -662,7 +677,15 @@ function! fzf#vim#commits(...)
|
|||||||
endif
|
endif
|
||||||
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
|
endfunction
|
||||||
|
|
||||||
" ----------------------------------------------------------------------------
|
" ----------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -90,6 +90,7 @@ COMMANDS *fzf-vim-commands*
|
|||||||
`History/` | Search history
|
`History/` | Search history
|
||||||
`Snippets` | Snippets ({UltiSnips}{6})
|
`Snippets` | Snippets ({UltiSnips}{6})
|
||||||
`Commits` | Git commits (requires {fugitive.vim}{7})
|
`Commits` | Git commits (requires {fugitive.vim}{7})
|
||||||
|
`BCommits` | Git commits for the current buffer
|
||||||
`Commands` | Commands
|
`Commands` | Commands
|
||||||
`Helptags` | Help tags [1]
|
`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 Helptags call fzf#vim#helptags(s:w(<bang>0))
|
||||||
command! -bang Windows call fzf#vim#windows(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 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)
|
function! s:history(arg, bang)
|
||||||
let bang = a:bang || a:arg[len(a:arg)-1] == '!'
|
let bang = a:bang || a:arg[len(a:arg)-1] == '!'
|
||||||
|
|||||||
Reference in New Issue
Block a user