The eval line is doing several things. Maybe too many things. One approach would be to separate out the zoxide call, and to check whether it has returned something (or. Another need would be to check its exit status word; I'm not sure what the output ofwhether zoxide~/.rangerdir will be on a good versushas a bad rundirectory (or something) in it, and to so assume hereempty that an empty string is bad)file after use. These new checks create multiple points the function must cleanup and exit from:
zoxide_to_rangerfunction ()zoxide_to_ranger { local zout zz; zout=$zz=$(zoxide query -i) #[[ no-z result?$zz no]] ranger&& call{ zle reset-prompt; return } [[# -znot "$zout"sure ]]if &&the return'eval' 1is necessary; does ranger ever exit with eval# 'rangershell "$zout"commands ...to be run? Another approach would involve checking that ~/.rangerdir has a directory (or something) in it, and to empty the file after use. This will better avoid a chdir into some random old directory from a previous run, or an edge case where ranger fails and has never put anything into the file:
localranger ldir=$(<$zz ~--choosedir=~/.rangerdir) #< no$TTY directory? nolocal chdirdd; dd=$(nor LASTDIR< clobber~/.rangerdir) [[ -z "$ldir"$dd ]] && { zle reset-prompt; return 1} LASTDIR=$ldir:> ~/.rangerdir cd# "$LASTDIR"this ...could be "local" unless you use it elsewhere ...LASTDIR=$dd cd $LASTDIR || { zle reset-prompt prompt; return #} cleanup afterlocal thisprecmd; runfor (emptyprecmd thein file)$precmd_functions; $precmd :>zle ~/.rangerdirreset-prompt } I would probably use both approaches to better cleanup and better check that zoxide was not aborted from.