My answer is based off of gzfrancisco's. However, I fix the "'-a' at index 2" issue, and I also ensure that a new prompt is printed after exiting ranger.
I put the following in ~/.config/fish/config.fish
:
function ranger-cd
set tempfile '/tmp/chosendir'
ranger --choosedir=$tempfile (pwd)
if test -f $tempfile
if [ (cat $tempfile) != (pwd) ]
cd (cat $tempfile)
end
end
rm -f $tempfile
end
function fish_user_key_bindings
bind \co 'ranger-cd ; commandline -f repaint'
end