forked from voldikss/vim-floaterm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfzf.vim
40 lines (38 loc) · 1.27 KB
/
fzf.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
" vim:sw=2:
" ============================================================================
" FileName: fzf.vim
" Author: voldikss <[email protected]>
" GitHub: https://github.com/voldikss
" ============================================================================
function! floaterm#wrapper#fzf#(cmd, jobopts, config) abort
let s:fzf_tmpfile = tempname()
let cmd = a:cmd
if cmd !~ '--preview'
if executable('bat')
let cmd .= ' --preview ' . shellescape('bat --style=numbers --color=always {}')
else
let cmd .= ' --preview ' . shellescape('cat -n {}')
endif
endif
let cmd .= ' > ' . s:fzf_tmpfile
let cmd = [&shell, &shellcmdflag, cmd]
let jobopts = {'on_exit': funcref('s:fzf_callback')}
call floaterm#util#deep_extend(a:jobopts, jobopts)
return [v:false, cmd]
endfunction
function! s:fzf_callback(job, data, event, opener) abort
if filereadable(s:fzf_tmpfile)
let filenames = readfile(s:fzf_tmpfile)
if !empty(filenames)
if has('nvim')
call floaterm#window#hide(bufnr('%'))
endif
let locations = []
for filename in filenames
let dict = {'filename': fnamemodify(filename, ':p')}
call add(locations, dict)
endfor
call floaterm#util#open(locations, a:opener)
endif
endif
endfunction