Sample Header Ad - 728x90

Confusing pushd/popd behaviour when sourcing script in zsh

2 votes
3 answers
482 views
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
Asked by paradroid (1245 rep)
May 15, 2023, 10:28 PM
Last activity: May 16, 2023, 10:50 AM