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

Silently restoring .zshrc.pre-oh-my-zsh during uninstall could overwrite
years of user config with a stale backup from install time, with no
warning or recovery path. Fixes #13156, fixes #13328.

Changes:
- Clarify the timestamped backup message so users know it holds their
  current config, not a throwaway file
- Show the modification date of the pre-OMZ backup before restoring it
- Prompt for confirmation before restoring; default is N (no restore)
- If user declines, print both file paths so they can merge manually
- Cross-platform date: tries macOS `date -r` then GNU `stat -c %Y`

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Sri Harsha Ponukumati 2026-07-02 13:58:52 -07:00
commit 7b6e0d8cbb

View file

@ -23,18 +23,40 @@ 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
echo ""
echo "Your files are at:"
echo " Current config : ${ZSHRC_SAVE}"
echo " Pre-OMZ backup : ${ZSHRC_ORIG}"
echo "You can review and merge them manually."
fi
fi
else
echo "No original zsh config found"
echo "No original zsh config found."
if [ -n "$ZSHRC_SAVE" ]; then
echo "Your current config is saved at ${ZSHRC_SAVE}."
fi
fi
echo "Thanks for trying out Oh My Zsh. It's been uninstalled."