Implement --selectfile functionality
Closed this issue · 3 comments
lkmill commented
The only reason i am using my own custom implementation of this functionality is because i really like the option of 1. opening ranger in the current working directory or 2. opening the current file's directory (and selecting the current file) using the --selectfile argument to ranger.
Would you perhaps be open to implementing this?
I did not create a PR because i do not know how you would like to implement it. I have done it like so (original code copied from http://ornicar.github.io/2011/02/12/ranger-as-vim-file-manager.html which does not exist anymore):
nmap <leader>r :call Ranger(1)<cr>
nmap <leader>R :call Ranger(0)<cr>
function! Ranger(cwd)
let currentFile = expand("%:p")
let rangerCallback = { 'name': 'ranger' }
function! rangerCallback.on_exit(id, code)
Bclose!
try
if filereadable('/tmp/chosenfile')
exec system('sed -ie "s/ /\\\ /g" /tmp/chosenfile')
exec 'argadd ' . system('cat /tmp/chosenfile | tr "\\n" " "')
exec 'edit ' . system('head -n1 /tmp/chosenfile')
call system('rm /tmp/chosenfile')
endif
endtry
endfunction
enew
if a:cwd
call termopen('ranger --choosefiles=/tmp/chosenfile', rangerCallback)
else
call termopen('ranger --choosefiles=/tmp/chosenfile --selectfile=' . currentFile, rangerCallback)
endif
startinsert
endfunction
francoiscabrol commented
Hey thank you for your code, I have started to implement it on a branch.
lkmill commented
Great stuff, thanks!
francoiscabrol commented
Welcome! :)