forked from liuchengxu/vim-clap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfiles.vim
84 lines (69 loc) · 2.45 KB
/
files.vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
" Author: liuchengxu <[email protected]>
" Description: List the files.
let s:save_cpo = &cpoptions
set cpoptions&vim
let s:files = {}
let s:default_opts = {
\ 'fd': '--type f',
\ 'rg': '--files',
\ 'git': 'ls-tree -r --name-only HEAD',
\ 'find': '. -type f',
\ }
let s:options = filter(['fd', 'rg', 'git', 'find'], 'executable(v:val)')
if empty(s:options)
let s:default_finder = v:null
let s:default_source = ['No usable tools found for the files provider']
else
let s:default_finder = s:options[0]
let s:default_source = join([s:default_finder, s:default_opts[s:default_finder]], ' ')
endif
function! s:files.source() abort
call clap#rooter#try_set_cwd()
if has_key(g:clap.context, 'name-only')
let g:__clap_builtin_line_splitter_enum = 'FileNameOnly'
endif
if has_key(g:clap.context, 'finder')
let finder = g:clap.context.finder
return finder.' '.join(g:clap.provider.args, ' ')
elseif g:clap.provider.args == ['--hidden']
if s:default_finder ==# 'fd' || s:default_finder ==# 'rg'
return join([s:default_finder, s:default_opts[s:default_finder], '--hidden'], ' ')
endif
endif
return s:default_source
endfunction
function! s:into_filename(line) abort
if g:clap_enable_icon && clap#maple#is_available()
return a:line[4:]
else
return a:line
endif
endfunction
function! clap#provider#files#sink_impl(selected) abort
let fpath = s:into_filename(a:selected)
call clap#sink#edit_with_open_action(fpath)
endfunction
function! clap#provider#files#sink_star_impl(lines) abort
call clap#util#open_quickfix(map(map(a:lines, 's:into_filename(v:val)'),
\ '{'.
\ '"filename": v:val,'.
\ '"text": strftime("Modified %b,%d %Y %H:%M:%S", getftime(v:val))." ".getfperm(v:val)'.
\ '}'))
endfunction
function! clap#provider#files#on_move_impl() abort
call clap#preview#file(s:into_filename(g:clap.display.getcurline()))
endfunction
function! s:files.on_exit() abort
if exists('g:__clap_builtin_line_splitter_enum')
unlet g:__clap_builtin_line_splitter_enum
endif
endfunction
let s:files.sink = function('clap#provider#files#sink_impl')
let s:files['sink*'] = function('clap#provider#files#sink_star_impl')
let s:files.on_move = function('clap#provider#files#on_move_impl')
let s:files.enable_rooter = v:true
let s:files.support_open_action = v:true
let s:files.syntax = 'clap_files'
let g:clap#provider#files# = s:files
let &cpoptions = s:save_cpo
unlet s:save_cpo