GitFiles?

This commit is contained in:
Junegunn Choi
2016-04-21 01:01:59 +09:00
parent 7066024d6f
commit 9e2aa1a710
4 changed files with 25 additions and 7 deletions

View File

@@ -50,7 +50,8 @@ Commands
| Command | List | | Command | List |
| --- | --- | | --- | --- |
| `Files [PATH]` | Files (similar to `:FZF`) | | `Files [PATH]` | Files (similar to `:FZF`) |
| `GitFiles` | Git files | | `GitFiles` | Git files (git ls-files) |
| `GitFiles?` | Git files (git status) |
| `Buffers` | Open buffers | | `Buffers` | Open buffers |
| `Colors` | Color schemes | | `Colors` | Color schemes |
| `Ag [PATTERN]` | [ag][ag] search result (`ALT-A` to select all, `ALT-D` to deselect all) | | `Ag [PATTERN]` | [ag][ag] search result (`ALT-A` to select all, `ALT-D` to deselect all) |

View File

@@ -357,18 +357,34 @@ function! fzf#vim#history(...)
endfunction endfunction
" ------------------------------------------------------------------ " ------------------------------------------------------------------
" GitFiles " GitFiles[?]
" ------------------------------------------------------------------ " ------------------------------------------------------------------
function! fzf#vim#gitfiles(...) function! s:git_status_sink(lines) abort
if len(a:lines) < 2
return
endif
let lines = extend(a:lines[0:0], map(a:lines[1:], 'v:val[3:]'))
return s:common_sink(lines)
endfunction
function! fzf#vim#gitfiles(args, ...)
let root = systemlist('git rev-parse --show-toplevel')[0] let root = systemlist('git rev-parse --show-toplevel')[0]
if v:shell_error if v:shell_error
return s:warn('Not in git repo') return s:warn('Not in git repo')
endif endif
if a:args !~ '^?'
return s:fzf(fzf#vim#wrap({
\ 'source': 'git ls-files',
\ 'dir': root,
\ 'options': '-m --prompt "GitFiles> "'
\}), a:000)
endif
return s:fzf(fzf#vim#wrap({ return s:fzf(fzf#vim#wrap({
\ 'source': 'git ls-tree --name-only -r HEAD', \ 'source': 'git -c color.status=always status --short',
\ 'dir': root, \ 'dir': root,
\ 'options': '-m --prompt "GitFiles> "' \ 'sink*': s:function('s:git_status_sink'),
\ 'options': '--ansi --multi --nth 2..,.. --prompt "GitFiles?> "'
\}), a:000) \}), a:000)
endfunction endfunction

View File

@@ -75,7 +75,8 @@ COMMANDS *fzf-vim-commands*
Command | List ~ Command | List ~
-----------------+------------------------------------------------------------------- -----------------+-------------------------------------------------------------------
`Files[PATH]` | Files (similar to `:FZF` ) `Files[PATH]` | Files (similar to `:FZF` )
`GitFiles` | Git files `GitFiles` | Git files (git ls-files)
`GitFiles?` | Git files (git status)
`Buffers` | Open buffers `Buffers` | Open buffers
`Colors` | Color schemes `Colors` | Color schemes
`Ag[PATTERN]` | {ag}{5} search result (ALT-A to select all, ALT-D to deselect all) `Ag[PATTERN]` | {ag}{5} search result (ALT-A to select all, ALT-D to deselect all)

View File

@@ -43,7 +43,7 @@ endfunction
call s:defs([ call s:defs([
\'command! -bang -nargs=? -complete=dir Files call fzf#vim#files(<q-args>, s:w(<bang>0))', \'command! -bang -nargs=? -complete=dir Files call fzf#vim#files(<q-args>, s:w(<bang>0))',
\'command! -bang GitFiles call fzf#vim#gitfiles(s:w(<bang>0))', \'command! -bang -nargs=? GitFiles call fzf#vim#gitfiles(<q-args>, s:w(<bang>0))',
\'command! -bang Buffers call fzf#vim#buffers(s:w(<bang>0))', \'command! -bang Buffers call fzf#vim#buffers(s:w(<bang>0))',
\'command! -bang Lines call fzf#vim#lines(s:w(<bang>0))', \'command! -bang Lines call fzf#vim#lines(s:w(<bang>0))',
\'command! -bang BLines call fzf#vim#buffer_lines(s:w(<bang>0))', \'command! -bang BLines call fzf#vim#buffer_lines(s:w(<bang>0))',