fix(uninstall): respect ZDOTDIR and ZSH environment variables

This commit is contained in:
Codebuff Contributor 2026-05-16 07:05:50 +06:00
commit 1b8bb3615f

View file

@ -16,22 +16,27 @@ if [ "$confirmation" != y ] && [ "$confirmation" != Y ]; then
exit
fi
echo "Removing ~/.oh-my-zsh"
if [ -d ~/.oh-my-zsh ]; then
rm -rf ~/.oh-my-zsh
# Use $ZSH if set, otherwise fall back to ~/.oh-my-zsh
: ${ZSH:=~/.oh-my-zsh}
# Use $ZDOTDIR if set, otherwise fall back to $HOME
: ${ZDOTDIR:=$HOME}
echo "Removing $ZSH"
if [ -d "$ZSH" ]; then
rm -rf "$ZSH"
fi
if [ -e ~/.zshrc ]; then
ZSHRC_SAVE=~/.zshrc.omz-uninstalled-$(date +%Y-%m-%d_%H-%M-%S)
echo "Found ~/.zshrc -- Renaming to ${ZSHRC_SAVE}"
mv ~/.zshrc "${ZSHRC_SAVE}"
if [ -e "$ZDOTDIR/.zshrc" ]; then
ZSHRC_SAVE="$ZDOTDIR/.zshrc.omz-uninstalled-$(date +%Y-%m-%d_%H-%M-%S)"
echo "Found $ZDOTDIR/.zshrc -- Renaming to ${ZSHRC_SAVE}"
mv "$ZDOTDIR/.zshrc" "${ZSHRC_SAVE}"
fi
echo "Looking for original zsh config..."
ZSHRC_ORIG=~/.zshrc.pre-oh-my-zsh
ZSHRC_ORIG="$ZDOTDIR/.zshrc.pre-oh-my-zsh"
if [ -e "$ZSHRC_ORIG" ]; then
echo "Found $ZSHRC_ORIG -- Restoring to ~/.zshrc"
mv "$ZSHRC_ORIG" ~/.zshrc
echo "Found $ZSHRC_ORIG -- Restoring to $ZDOTDIR/.zshrc"
mv "$ZSHRC_ORIG" "$ZDOTDIR/.zshrc"
echo "Your original zsh config was restored."
else
echo "No original zsh config found"