-
Notifications
You must be signed in to change notification settings - Fork 81
/
broot.vim
66 lines (60 loc) · 1.96 KB
/
broot.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
" vim:sw=2:
" ============================================================================
" FileName: broot.vim
" Author: voldikss <dyzplus@gmail.com>
" GitHub: https://github.com/voldikss
" ============================================================================
let s:broot_default_confpath = fnamemodify('~/.config/broot/conf.hjson', ':p')
let s:broot_wrapper_confpath = fnamemodify(expand('<sfile>'), ':h') . '/broot.hjson'
let s:broot_confpath = s:broot_wrapper_confpath . ';' . s:broot_default_confpath
let s:broot_wrapper_config = [
\ '{',
\ ' verbs: [',
\ ' {',
\ ' invocation: terminal',
\ ' key: enter',
\ ' execution: "echo {line} {file}"',
\ ' leave_broot: true',
\ ' apply_to: file',
\ ' }',
\ ' ]',
\ '}',
\ ]
call writefile(s:broot_wrapper_config, s:broot_wrapper_confpath)
function! floaterm#wrapper#broot#(cmd, jobopts, config) abort
let s:broot_tmpfile = tempname()
let original_dir = getcwd()
lcd %:p:h
let cmdlist = split(a:cmd)
let cmd = printf(
\ '%s --conf "%s" > "%s"',
\ a:cmd,
\ s:broot_confpath,
\ s:broot_tmpfile
\ )
exe "lcd " . original_dir
let cmd = [&shell, &shellcmdflag, cmd]
let jobopts = {'on_exit': funcref('s:broot_callback')}
call floaterm#util#deep_extend(a:jobopts, jobopts)
return [v:false, cmd]
endfunction
function! s:broot_callback(job, data, event, opener) abort
if filereadable(s:broot_tmpfile)
let filenames = readfile(s:broot_tmpfile)
if !empty(filenames)
if has('nvim')
call floaterm#window#hide(bufnr('%'))
endif
let locations = []
for filename in filenames
let lnum_file = split(filename)
let dict = {
\ 'filename': fnamemodify(lnum_file[1], ':p'),
\ 'lnum': lnum_file[0],
\ }
call add(locations, dict)
endfor
call floaterm#util#open(locations, a:opener)
endif
endif
endfunction