more precise implementation of chpwd and chpwd_functions from Zsh, update #2819