in zsh - I make heavy use of command_not_found_handler - to allow various tools I have defined to run at the shell level - mainly to jump me around the place.
but I'd really like to know if there's a similar way to trap "permission denied". What I'm actually trying to achieve is to be able to change into a directory without typing cd - so I was thinking I could drop something like this into .zshrc:
permission_denied_handler() {
if [ -d $1 ]; then
echo changing to $1
cd $1
return 0
else
echo permission denied
return 127
fi
}
but of course that doesn't work. Is there a way to achieve what I want? The reason I want it is because I have the command not found handler - so for instance if I want to jump to say my downloads directory from anywhere on my machine, I just say "downloads" - but if I'm in ~ - instead of triggering command not found, it sees the directory and just says permission denied :(
and the reason I use command_not_found instead of just something that builds aliases is that I'm constantly adding new commands - so if I have 8 shell windows open, in this way, as soon as I add a new command, it's active in all windows - but if I added them to .zshrc or something, I'd have to refresh or restart the shells.