fix(uninstall): prompt before restoring pre-OMZ zshrc backup (#13849)

Fixes #13156
Fixes #13328
This commit is contained in:
Sri Harsha Ponukumati authored and GitHub committed 2026-11-27 18:30:43 -08:00
1 parent 5873e1cfec
commit 5c7cd91615
1 file changed
+34 -5
+34 -5
View File
@@ -23,18 +23,47 @@ fi
if [ -e ~/.zshrc ]; then
ZSHRC_SAVE=~/.zshrc.omz-uninstalled-$(date +%Y-%m-%d_%H-%M-%S)
echo "Found ~/.zshrc -- Renaming to ${ZSHRC_SAVE}"
echo "Found ~/.zshrc -- Saving your current config to ${ZSHRC_SAVE}"
echo " (this file contains your current zsh configuration)"
mv ~/.zshrc "${ZSHRC_SAVE}"
fi
echo "Looking for original zsh config..."
ZSHRC_ORIG=~/.zshrc.pre-oh-my-zsh
if [ -e "$ZSHRC_ORIG" ]; then
echo "Found $ZSHRC_ORIG -- Restoring to ~/.zshrc"
mv "$ZSHRC_ORIG" ~/.zshrc
echo "Your original zsh config was restored."
ZSHRC_ORIG_DATE=$(date -r "$ZSHRC_ORIG" "+%Y-%m-%d" 2>/dev/null || date -d "@$(stat -c %Y "$ZSHRC_ORIG" 2>/dev/null)" "+%Y-%m-%d" 2>/dev/null || echo "unknown date")
echo "Found $ZSHRC_ORIG (last modified: ${ZSHRC_ORIG_DATE})"
echo "This is the zsh config that existed before Oh My Zsh was installed."
printf "Restore it as ~/.zshrc? [y/N] "
read -r restore_confirmation
if [ "$restore_confirmation" = y ] || [ "$restore_confirmation" = Y ]; then
mv "$ZSHRC_ORIG" ~/.zshrc
echo "Your original zsh config was restored to ~/.zshrc."
if [ -n "$ZSHRC_SAVE" ]; then
echo "Your Oh My Zsh config is saved at ${ZSHRC_SAVE} if you need it."
fi
else
echo "Skipping restore."
if [ -n "$ZSHRC_SAVE" ]; then
mv "${ZSHRC_SAVE}" ~/.zshrc
echo "Your current zsh config has been kept at ~/.zshrc."
echo "Your pre-OMZ backup is still at ${ZSHRC_ORIG} if you need it."
fi
fi
else
echo "No original zsh config found"
echo "No original zsh config found."
if [ -n "$ZSHRC_SAVE" ]; then
mv "${ZSHRC_SAVE}" ~/.zshrc
echo "Your current zsh config has been kept at ~/.zshrc."
fi
fi
# Warn if the active .zshrc still sources oh-my-zsh
if [ -f ~/.zshrc ] && command grep -q 'source.*oh-my-zsh\.sh' ~/.zshrc 2>/dev/null; then
echo ""
echo "Note: ~/.zshrc still contains a line sourcing oh-my-zsh.sh."
echo "Since oh-my-zsh has been removed, that line will cause an error"
echo "on every new shell. You may want to remove or comment it out."
fi
echo "Thanks for trying out Oh My Zsh. It's been uninstalled."