Hope you're doing well.
I have the following in my .zshrc
:
# 1. invoke zoxide to pick dir
# 2. open target dir in ranger
# 3. when exiting ranger, cd into last dir
zoxide_to_ranger () {
eval 'ranger "$(zoxide query -i)" --choosedir=$HOME/.rangerdir < $TTY'
LASTDIR=$(< ~/.rangerdir)
cd "$LASTDIR" || exit
# ensure `precmds` are run after `cd`
local precmd
for precmd in $precmd_functions; do
$precmd
done
zle reset-prompt
}
zle -N zoxide_to_ranger
bindkey '^f' zoxide_to_ranger
As suggested in the inline comment, it's a handy tool such that when I trigger Ctrl-f
, it'll prompt me a fzf menu, and upon selection it'll open ranger in that dir.
The problem is that, when I want to cancel selection by pressing Esc
, it'll still open up ranger and send me the home dir, which is not what I want.
So my question is, how do I cancel such a zle function after triggering the bindkey?
Config:
zsh 5.9 (x86_64-pc-linux-gnu)
OS: Manjaro Linux
Any input is much appreciated. Thank you:)