|
23 | 23 |
|
24 | 24 |
|
25 | 25 | " ================ Ranger =======================
|
| 26 | +if exists('g:ranger_choice_file') |
| 27 | + if empty(glob(g:ranger_choice_file)) |
| 28 | + let s:choice_file_path = g:ranger_choice_file |
| 29 | + else |
| 30 | + echom "Message from *Ranger.vim* :" |
| 31 | + echom "You've set the g:ranger_choice_file variable." |
| 32 | + echom "Please use the path for a file that does not already exist." |
| 33 | + echom "Using /tmp/chosenfile for now..." |
| 34 | + endif |
| 35 | +endif |
| 36 | + |
| 37 | +if !exists('s:choice_file_path') |
| 38 | + let s:choice_file_path = '/tmp/chosenfile' |
| 39 | +endif |
| 40 | + |
26 | 41 | if has('nvim')
|
27 | 42 | function! OpenRangerIn(path, edit_cmd)
|
28 | 43 | let currentPath = expand(a:path)
|
29 | 44 | let rangerCallback = { 'name': 'ranger', 'edit_cmd': a:edit_cmd }
|
30 | 45 | function! rangerCallback.on_exit(id, code, _event)
|
31 | 46 | silent! Bclose!
|
32 | 47 | try
|
33 |
| - if filereadable('/tmp/chosenfile') |
34 |
| - exec system('sed -ie "s/ /\\\ /g" /tmp/chosenfile') |
35 |
| - exec 'argadd ' . system('cat /tmp/chosenfile | tr "\\n" " "') |
36 |
| - exec self.edit_cmd . system('head -n1 /tmp/chosenfile') |
37 |
| - call system('rm /tmp/chosenfile') |
| 48 | + if filereadable(s:choice_file_path) |
| 49 | + exec system('sed -ie "s/ /\\\ /g" ' . s:choice_file_path) |
| 50 | + exec 'argadd ' . system('cat ' . s:choice_file_path . ' | tr "\\n" " "') |
| 51 | + exec self.edit_cmd . system('head -n1 ' . s:choice_file_path) |
| 52 | + call system('rm ' . s:choice_file_path) |
38 | 53 | endif
|
39 | 54 | endtry
|
40 | 55 | endfunction
|
41 | 56 | enew
|
42 | 57 | if isdirectory(currentPath)
|
43 |
| - call termopen('ranger --choosefiles=/tmp/chosenfile "' . currentPath . '"', rangerCallback) |
| 58 | + call termopen('ranger --choosefiles=' . s:choice_file_path . ' "' . currentPath . '"', rangerCallback) |
44 | 59 | else
|
45 |
| - call termopen('ranger --choosefiles=/tmp/chosenfile --selectfile="' . currentPath . '"', rangerCallback) |
| 60 | + call termopen('ranger --choosefiles=' . s:choice_file_path . ' --selectfile="' . currentPath . '"', rangerCallback) |
46 | 61 | endif
|
47 | 62 | startinsert
|
48 | 63 | endfunction
|
49 | 64 | else
|
50 | 65 | function! OpenRangerIn(path, edit_cmd)
|
51 | 66 | let currentPath = expand(a:path)
|
52 |
| - exec 'silent !ranger --choosefiles=/tmp/chosenfile --selectfile="' . currentPath . '"' |
53 |
| - if filereadable('/tmp/chosenfile') |
54 |
| - exec system('sed -ie "s/ /\\\ /g" /tmp/chosenfile') |
55 |
| - exec 'argadd ' . system('cat /tmp/chosenfile | tr "\\n" " "') |
56 |
| - exec a:edit_cmd . system('head -n1 /tmp/chosenfile') |
57 |
| - call system('rm /tmp/chosenfile') |
| 67 | + exec 'silent !ranger --choosefiles=' . s:choice_file_path . ' --selectfile="' . currentPath . '"' |
| 68 | + if filereadable(s:choice_file_path) |
| 69 | + exec system('sed -ie "s/ /\\\ /g" ' . s:choice_file_path) |
| 70 | + exec 'argadd ' . system('cat ' . s:choice_file_path . ' | tr "\\n" " "') |
| 71 | + exec a:edit_cmd . system('head -n1 ' . s:choice_file_path) |
| 72 | + call system('rm ' . s:choice_file_path) |
58 | 73 | endif
|
59 | 74 | redraw!
|
60 | 75 | endfun
|
@@ -86,7 +101,7 @@ endfunction
|
86 | 101 | " Open Ranger in the directory passed by argument
|
87 | 102 | function! OpenRangerOnVimLoadDir(argv_path)
|
88 | 103 | " Open Ranger
|
89 |
| - let path = expand(a:argv_path) |
| 104 | + let path = expand(a:argv_path) |
90 | 105 | call OpenRangerIn(path, "edit")
|
91 | 106 |
|
92 | 107 | " Delete the empty buffer created by vim
|
|
0 commit comments