From 43b3126b5cd2253330edf73930d37f17eaf4328f Mon Sep 17 00:00:00 2001 From: Andrew Janke Date: Wed, 23 Sep 2015 18:41:48 -0400 Subject: installer: use timestamped backups to preserve all old zshrcs --- tools/install.sh | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'tools/install.sh') diff --git a/tools/install.sh b/tools/install.sh index e69ce4b83..66da05690 100755 --- a/tools/install.sh +++ b/tools/install.sh @@ -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}" -- cgit v1.2.3-70-g09d2