mirror of
https://github.com/junegunn/fzf.vim.git
synced 2025-12-06 04:34:26 +08:00
[[B]Commits] Support arguments for git-log (#1455)
* [[B]Commits] Support arguments for git-log
Add support for command arguments that are passed to git-log (e.g.
:Commits -S foo -3).
The place of insertion is relevant. Generally the arguments should come
at the end to overwrite existing flags if necessary, but need to come
before the pathspec (i.e. `fzf#shellescape(current)`) in BCommits.
* [[B]Commits] Make sure all positional arguments are optional
Test cases:
" With default options
%call fzf#vim#commits()
" Full screen
%call fzf#vim#commits(1)
" Not full screen
%call fzf#vim#commits(0)
" With extra fzf options
%call fzf#vim#commits({ 'up': '50%', 'options': '--no-color' })
" With extra fzf options (with preview) and in full screen
%call fzf#vim#commits(fzf#vim#with_preview({ 'options': '--no-color', 'placeholder': '' }), 1)
" With extra git log options
%call fzf#vim#commits('-S foo')
" With extra git log options in full screen
%call fzf#vim#commits('-S foo', 1)
" With extra git log options and fzf options
%call fzf#vim#commits('-S foo', { 'options': '--no-color' })
" In full-screen
%call fzf#vim#commits('-S foo', { 'options': '--no-color' }, 1)
" Command form
Commits
Commits!
Commits -S foo
Commits! -S foo
* [Commits] Enable file completion for arguments
This gets handy when BCommits is too narrow (e.g. multiple files or a
folder is specified).
Co-authored-by: Junegunn Choi <junegunn.c@gmail.com>
This commit is contained in:
@@ -1267,16 +1267,19 @@ function! s:commits(range, buffer_local, args)
|
||||
let managed = !v:shell_error
|
||||
endif
|
||||
|
||||
let args = copy(a:args)
|
||||
let log_opts = len(args) && type(args[0]) == type('') ? remove(args, 0) : ''
|
||||
|
||||
if len(a:range) || a:buffer_local
|
||||
if !managed
|
||||
return s:warn('The current buffer is not in the working tree')
|
||||
endif
|
||||
let source .= len(a:range)
|
||||
\ ? printf(' -L %d,%d:%s --no-patch', a:range[0], a:range[1], fzf#shellescape(current))
|
||||
\ : (' --follow '.fzf#shellescape(current))
|
||||
\ ? join([printf(' -L %d,%d:%s --no-patch', a:range[0], a:range[1], fzf#shellescape(current)), log_opts])
|
||||
\ : join([' --follow', log_opts, fzf#shellescape(current)])
|
||||
let command = 'BCommits'
|
||||
else
|
||||
let source .= ' --graph'
|
||||
let source .= join([' --graph', log_opts])
|
||||
let command = 'Commits'
|
||||
endif
|
||||
|
||||
@@ -1303,7 +1306,7 @@ function! s:commits(range, buffer_local, args)
|
||||
\ ['--preview', 'echo {} | grep -o "[a-f0-9]\{7,\}" | head -1 | xargs ' . prefix . 'show -O'.fzf#shellescape(orderfile).' --format=format: --color=always ' . suffix])
|
||||
endif
|
||||
|
||||
return s:fzf(a:buffer_local ? 'bcommits' : 'commits', options, a:args)
|
||||
return s:fzf(a:buffer_local ? 'bcommits' : 'commits', options, args)
|
||||
endfunction
|
||||
|
||||
" Heuristically determine if the user specified a range
|
||||
@@ -1320,6 +1323,7 @@ function! s:given_range(line1, line2)
|
||||
return []
|
||||
endfunction
|
||||
|
||||
" [git-log-args], [spec (dict)], [fullscreen (bool)]
|
||||
function! fzf#vim#commits(...) range
|
||||
if exists('b:fzf_winview')
|
||||
call winrestview(b:fzf_winview)
|
||||
@@ -1328,6 +1332,7 @@ function! fzf#vim#commits(...) range
|
||||
return s:commits(s:given_range(a:firstline, a:lastline), 0, a:000)
|
||||
endfunction
|
||||
|
||||
" [git-log-args], [spec (dict)], [fullscreen (bool)]
|
||||
function! fzf#vim#buffer_commits(...) range
|
||||
if exists('b:fzf_winview')
|
||||
call winrestview(b:fzf_winview)
|
||||
|
||||
@@ -45,28 +45,28 @@ function! s:defs(commands)
|
||||
endfunction
|
||||
|
||||
call s:defs([
|
||||
\'command! -bang -nargs=? -complete=dir Files call fzf#vim#files(<q-args>, fzf#vim#with_preview(), <bang>0)',
|
||||
\'command! -bang -nargs=? GitFiles call fzf#vim#gitfiles(<q-args>, fzf#vim#with_preview(<q-args> == "?" ? { "placeholder": "" } : {}), <bang>0)',
|
||||
\'command! -bang -nargs=? GFiles call fzf#vim#gitfiles(<q-args>, fzf#vim#with_preview(<q-args> == "?" ? { "placeholder": "" } : {}), <bang>0)',
|
||||
\'command! -bar -bang -nargs=? -complete=buffer Buffers call fzf#vim#buffers(<q-args>, fzf#vim#with_preview({ "placeholder": "{1}" }), <bang>0)',
|
||||
\'command! -bang -nargs=* Lines call fzf#vim#lines(<q-args>, <bang>0)',
|
||||
\'command! -bang -nargs=* BLines call fzf#vim#buffer_lines(<q-args>, <bang>0)',
|
||||
\'command! -bar -bang Colors call fzf#vim#colors(<bang>0)',
|
||||
\'command! -bang -nargs=+ -complete=dir Locate call fzf#vim#locate(<q-args>, fzf#vim#with_preview(), <bang>0)',
|
||||
\'command! -bang -nargs=* Ag call fzf#vim#ag(<q-args>, fzf#vim#with_preview(), <bang>0)',
|
||||
\'command! -bang -nargs=* Rg call fzf#vim#grep("rg --column --line-number --no-heading --color=always --smart-case -- ".shellescape(<q-args>), 1, fzf#vim#with_preview(), <bang>0)',
|
||||
\'command! -bang -nargs=* Tags call fzf#vim#tags(<q-args>, fzf#vim#with_preview({ "placeholder": "--tag {2}:{-1}:{3..}" }), <bang>0)',
|
||||
\'command! -bang -nargs=* BTags call fzf#vim#buffer_tags(<q-args>, fzf#vim#with_preview({ "placeholder": "{2}:{3..}" }), <bang>0)',
|
||||
\'command! -bar -bang Snippets call fzf#vim#snippets(<bang>0)',
|
||||
\'command! -bar -bang Commands call fzf#vim#commands(<bang>0)',
|
||||
\'command! -bar -bang Marks call fzf#vim#marks(<bang>0)',
|
||||
\'command! -bar -bang Helptags call fzf#vim#helptags(fzf#vim#with_preview({ "placeholder": "--tag {2}:{3}:{4}" }), <bang>0)',
|
||||
\'command! -bar -bang Windows call fzf#vim#windows(<bang>0)',
|
||||
\'command! -bar -bang -range=% Commits let b:fzf_winview = winsaveview() | <line1>,<line2>call fzf#vim#commits(fzf#vim#with_preview({ "placeholder": "" }), <bang>0)',
|
||||
\'command! -bar -bang -range=% BCommits let b:fzf_winview = winsaveview() | <line1>,<line2>call fzf#vim#buffer_commits(fzf#vim#with_preview({ "placeholder": "" }), <bang>0)',
|
||||
\'command! -bar -bang Maps call fzf#vim#maps("n", <bang>0)',
|
||||
\'command! -bar -bang Filetypes call fzf#vim#filetypes(<bang>0)',
|
||||
\'command! -bang -nargs=* History call s:history(<q-args>, fzf#vim#with_preview(), <bang>0)'])
|
||||
\'command! -bang -nargs=? -complete=dir Files call fzf#vim#files(<q-args>, fzf#vim#with_preview(), <bang>0)',
|
||||
\'command! -bang -nargs=? GitFiles call fzf#vim#gitfiles(<q-args>, fzf#vim#with_preview(<q-args> == "?" ? { "placeholder": "" } : {}), <bang>0)',
|
||||
\'command! -bang -nargs=? GFiles call fzf#vim#gitfiles(<q-args>, fzf#vim#with_preview(<q-args> == "?" ? { "placeholder": "" } : {}), <bang>0)',
|
||||
\'command! -bar -bang -nargs=? -complete=buffer Buffers call fzf#vim#buffers(<q-args>, fzf#vim#with_preview({ "placeholder": "{1}" }), <bang>0)',
|
||||
\'command! -bang -nargs=* Lines call fzf#vim#lines(<q-args>, <bang>0)',
|
||||
\'command! -bang -nargs=* BLines call fzf#vim#buffer_lines(<q-args>, <bang>0)',
|
||||
\'command! -bar -bang Colors call fzf#vim#colors(<bang>0)',
|
||||
\'command! -bang -nargs=+ -complete=dir Locate call fzf#vim#locate(<q-args>, fzf#vim#with_preview(), <bang>0)',
|
||||
\'command! -bang -nargs=* Ag call fzf#vim#ag(<q-args>, fzf#vim#with_preview(), <bang>0)',
|
||||
\'command! -bang -nargs=* Rg call fzf#vim#grep("rg --column --line-number --no-heading --color=always --smart-case -- ".shellescape(<q-args>), 1, fzf#vim#with_preview(), <bang>0)',
|
||||
\'command! -bang -nargs=* Tags call fzf#vim#tags(<q-args>, fzf#vim#with_preview({ "placeholder": "--tag {2}:{-1}:{3..}" }), <bang>0)',
|
||||
\'command! -bang -nargs=* BTags call fzf#vim#buffer_tags(<q-args>, fzf#vim#with_preview({ "placeholder": "{2}:{3..}" }), <bang>0)',
|
||||
\'command! -bar -bang Snippets call fzf#vim#snippets(<bang>0)',
|
||||
\'command! -bar -bang Commands call fzf#vim#commands(<bang>0)',
|
||||
\'command! -bar -bang Marks call fzf#vim#marks(<bang>0)',
|
||||
\'command! -bar -bang Helptags call fzf#vim#helptags(fzf#vim#with_preview({ "placeholder": "--tag {2}:{3}:{4}" }), <bang>0)',
|
||||
\'command! -bar -bang Windows call fzf#vim#windows(<bang>0)',
|
||||
\'command! -bar -bang -nargs=* -range=% -complete=file Commits let b:fzf_winview = winsaveview() | <line1>,<line2>call fzf#vim#commits(<q-args>, fzf#vim#with_preview({ "placeholder": "" }), <bang>0)',
|
||||
\'command! -bar -bang -nargs=* -range=% BCommits let b:fzf_winview = winsaveview() | <line1>,<line2>call fzf#vim#buffer_commits(<q-args>, fzf#vim#with_preview({ "placeholder": "" }), <bang>0)',
|
||||
\'command! -bar -bang Maps call fzf#vim#maps("n", <bang>0)',
|
||||
\'command! -bar -bang Filetypes call fzf#vim#filetypes(<bang>0)',
|
||||
\'command! -bang -nargs=* History call s:history(<q-args>, fzf#vim#with_preview(), <bang>0)'])
|
||||
|
||||
function! s:history(arg, extra, bang)
|
||||
let bang = a:bang || a:arg[len(a:arg)-1] == '!'
|
||||
|
||||
Reference in New Issue
Block a user