1
0
Fork 0
mirror of https://github.com/ohmyzsh/ohmyzsh.git synced 2024-11-11 00:10:08 +00:00

installer: use timestamped backups to preserve all old zshrcs

This commit is contained in:
Andrew Janke 2015-09-23 18:41:48 -04:00 committed by Marc Cornellà
parent 153f5e11ed
commit 43b3126b5c
2 changed files with 28 additions and 9 deletions

View file

@ -84,10 +84,28 @@ setup_ohmyzsh() {
}
setup_zshrc() {
# Keep most recent old .zshrc at .zshrc.pre-oh-my-zsh, and older ones
# with datestamp of installation that moved them aside, so we never actually
# destroy a user's original zshrc
echo "${BLUE}Looking for an existing zsh config...${RESET}"
# Must use this exact name so uninstall.sh can find it
OLD_ZSHRC=~/.zshrc.pre-oh-my-zsh
if [ -f ~/.zshrc ] || [ -h ~/.zshrc ]; then
echo "${YELLOW}Found ~/.zshrc.${GREEN} Backing up to ~/.zshrc.pre-oh-my-zsh.${RESET}"
mv ~/.zshrc ~/.zshrc.pre-oh-my-zsh
if [ -e "$OLD_ZSHRC" ]; then
OLD_OLD_ZSHRC="${OLD_ZSHRC}-$(date +%Y-%m-%d_%H-%M-%S)"
if [ -e "$OLD_OLD_ZSHRC" ]; then
error "$OLD_OLD_ZSHRC exists. Can't back up ${OLD_ZSHRC}"
error "re-run the installer again in a couple of seconds"
exit 1
fi
mv "$OLD_ZSHRC" "${OLD_OLD_ZSHRC}"
echo "${YELLOW}Found old ~/.zshrc.pre-oh-my-zsh." \
"${GREEN}Backing up to ${OLD_OLD_ZSHRC}${RESET}"
fi
echo "${YELLOW}Found ~/.zshrc.${RESET} ${GREEN}Backing up to ${OLD_ZSHRC}${RESET}"
mv ~/.zshrc "$OLD_ZSHRC"
fi
echo "${BLUE}Using the Oh My Zsh template file and adding it to ~/.zshrc.${RESET}"

View file

@ -10,16 +10,17 @@ if [ -d ~/.oh-my-zsh ]; then
fi
echo "Looking for original zsh config..."
if [ -f ~/.zshrc.pre-oh-my-zsh ] || [ -h ~/.zshrc.pre-oh-my-zsh ]; then
echo "Found ~/.zshrc.pre-oh-my-zsh -- Restoring to ~/.zshrc";
ZSHRC_ORIG=~/.zshrc.pre-oh-my-zsh
if [ -e "$ZSHRC_ORIG" ]; then
echo "Found $ZSHRC_ORIG -- Restoring to ~/.zshrc"
if [ -f ~/.zshrc ] || [ -h ~/.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 ~/.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}"
fi
mv ~/.zshrc.pre-oh-my-zsh ~/.zshrc;
mv "$ZSHRC_ORIG" ~/.zshrc
echo "Your original zsh config was restored. Please restart your session."
else