I have a script which I source while in bash. It does various things and retains the $PWD I was in before sourcing it.
pushd ~/.dotfiles >/dev/null || exit 1
# Do various things
popd >/dev/null || exit 1
The script runs (mostly) fine in zsh too, but when I source it from the ~/.dotfiles location, I end up in the previous $OLDPWD after sourcing it.
It seems that zsh disregards the pushd line if the current location is already the same, so the popd command goes to the $OLDPWD from before when the script was sourced.
Is there a way of stopping zsh from ignoring the "redundant" pushd command, while also keeping the script compatible with bash?
I do have the following in my .zshrc, but it also happens when I unset them:
setopt AUTO_PUSHD PUSHD_SILENT PUSHD_IGNORE_DUPS