@@ -44,45 +44,44 @@ if !exists('s:choice_file_path')
4444 let s: choice_file_path = ' /tmp/chosenfile'
4545endif
4646
47+ function ! EditFiles (cmd)
48+ try
49+ if filereadable (s: choice_file_path )
50+ for f in readfile (s: choice_file_path )
51+ exec a: cmd . split (f , getcwd () . ' /' )[0 ]
52+ endfor
53+ call delete (s: choice_file_path )
54+ endif
55+ endtry
56+ endfunction
57+
58+ function ! GetRangerCmd (path )
59+ let currentPath = expand (a: path )
60+ let cmd = s: ranger_command . ' --choosefiles=' . s: choice_file_path
61+ if isdirectory (currentPath)
62+ return cmd . ' "' . currentPath . ' "'
63+ else
64+ return cmd . ' --selectfile="' . currentPath . ' "'
65+ endif
66+ endfunction
67+
4768if has (' nvim' )
4869 function ! OpenRangerIn (path , edit_cmd)
49- let currentPath = expand (a: path )
5070 let rangerCallback = { ' name' : ' ranger' , ' edit_cmd' : a: edit_cmd }
5171 function ! rangerCallback.on_exit (job_id, code, event )
5272 if a: code == 0
5373 silent ! Bclose!
5474 endif
55- try
56- if filereadable (s: choice_file_path )
57- for f in readfile (s: choice_file_path )
58- exec self .edit_cmd . split (f , getcwd () . ' /' )[0 ]
59- endfor
60- call delete (s: choice_file_path )
61- endif
62- endtry
75+ call EditFiles (self .edit_cmd)
6376 endfunction
6477 enew
65- if isdirectory (currentPath)
66- call termopen (s: ranger_command . ' --choosefiles=' . s: choice_file_path . ' "' . currentPath . ' "' , rangerCallback)
67- else
68- call termopen (s: ranger_command . ' --choosefiles=' . s: choice_file_path . ' --selectfile="' . currentPath . ' "' , rangerCallback)
69- endif
78+ call termopen (GetRangerCmd (a: path ), rangerCallback)
7079 startinsert
7180 endfunction
7281else
7382 function ! OpenRangerIn (path , edit_cmd)
74- let currentPath = expand (a: path )
75- if isdirectory (currentPath)
76- silent exec ' !' . s: ranger_command . ' --choosefiles=' . s: choice_file_path . ' "' . currentPath . ' "'
77- else
78- silent exec ' !' . s: ranger_command . ' --choosefiles=' . s: choice_file_path . ' --selectfile="' . currentPath . ' "'
79- endif
80- if filereadable (s: choice_file_path )
81- for f in readfile (s: choice_file_path )
82- exec a: edit_cmd . split (f , getcwd () . ' /' )[0 ]
83- endfor
84- call delete (s: choice_file_path )
85- endif
83+ silent exec ' !' . GetRangerCmd (a: path )
84+ call EditFiles (a: edit_cmd )
8685 redraw !
8786 " reset the filetype to fix the issue that happens
8887 " when opening ranger on VimEnter (with `vim .`)
0 commit comments