43b3126b5cd2253330edf73930d37f17eaf4328f

Author
Andrew Janke <andrew@apjanke.net>
Committer
Marc Cornellà <marc.cornella@live.com>
Date

Message

installer: use timestamped backups to preserve all old zshrcs

Diff

 1diff --git a/tools/install.sh b/tools/install.sh
 2index e69ce4b83c29508de28b5884de7849bd49d25906..66da056909b6ec61a77f26240bf804e3b7416dec 100755
 3--- a/tools/install.sh
 4+++ b/tools/install.sh
 5@@ -84,10 +84,28 @@ setup_ohmyzsh() {
 6 }
 7 
 8 setup_zshrc() {
 9+	# Keep most recent old .zshrc at .zshrc.pre-oh-my-zsh, and older ones
10+	# with datestamp of installation that moved them aside, so we never actually
11+	# destroy a user's original zshrc
12 	echo "${BLUE}Looking for an existing zsh config...${RESET}"
13+
14+	# Must use this exact name so uninstall.sh can find it
15+	OLD_ZSHRC=~/.zshrc.pre-oh-my-zsh
16 	if [ -f ~/.zshrc ] || [ -h ~/.zshrc ]; then
17-		echo "${YELLOW}Found ~/.zshrc.${GREEN} Backing up to ~/.zshrc.pre-oh-my-zsh.${RESET}"
18-		mv ~/.zshrc ~/.zshrc.pre-oh-my-zsh
19+		if [ -e "$OLD_ZSHRC" ]; then
20+			OLD_OLD_ZSHRC="${OLD_ZSHRC}-$(date +%Y-%m-%d_%H-%M-%S)"
21+			if [ -e "$OLD_OLD_ZSHRC" ]; then
22+				error "$OLD_OLD_ZSHRC exists. Can't back up ${OLD_ZSHRC}"
23+				error "re-run the installer again in a couple of seconds"
24+				exit 1
25+			fi
26+			mv "$OLD_ZSHRC" "${OLD_OLD_ZSHRC}"
27+
28+			echo "${YELLOW}Found old ~/.zshrc.pre-oh-my-zsh." \
29+				"${GREEN}Backing up to ${OLD_OLD_ZSHRC}${RESET}"
30+		fi
31+		echo "${YELLOW}Found ~/.zshrc.${RESET} ${GREEN}Backing up to ${OLD_ZSHRC}${RESET}"
32+		mv ~/.zshrc "$OLD_ZSHRC"
33 	fi
34 
35 	echo "${BLUE}Using the Oh My Zsh template file and adding it to ~/.zshrc.${RESET}"
36diff --git a/tools/uninstall.sh b/tools/uninstall.sh
37index bf2244be859720a99f10052ad64afc1b45978bee..9793be2a10a5da13f2f0dcb9346bbc3f606efbbf 100644
38--- a/tools/uninstall.sh
39+++ b/tools/uninstall.sh
40@@ -10,16 +10,17 @@ if [ -d ~/.oh-my-zsh ]; then
41 fi
42 
43 echo "Looking for original zsh config..."
44-if [ -f ~/.zshrc.pre-oh-my-zsh ] || [ -h ~/.zshrc.pre-oh-my-zsh ]; then
45-  echo "Found ~/.zshrc.pre-oh-my-zsh -- Restoring to ~/.zshrc";
46+ZSHRC_ORIG=~/.zshrc.pre-oh-my-zsh
47+if [ -e "$ZSHRC_ORIG" ]; then
48+  echo "Found $ZSHRC_ORIG -- Restoring to ~/.zshrc"
49 
50-  if [ -f ~/.zshrc ] || [ -h ~/.zshrc ]; then
51-    ZSHRC_SAVE=".zshrc.omz-uninstalled-$(date +%Y%m%d%H%M%S)";
52-    echo "Found ~/.zshrc -- Renaming to ~/${ZSHRC_SAVE}";
53-    mv ~/.zshrc ~/"${ZSHRC_SAVE}";
54+  if [ -e ~/.zshrc ]; then
55+    ZSHRC_SAVE=~/.zshrc.omz-uninstalled-$(date +%Y-%m-%d_%H-%M-%S)
56+    echo "Found ~/.zshrc -- Renaming to ${ZSHRC_SAVE}"
57+    mv ~/.zshrc "${ZSHRC_SAVE}"
58   fi
59 
60-  mv ~/.zshrc.pre-oh-my-zsh ~/.zshrc;
61+  mv "$ZSHRC_ORIG" ~/.zshrc
62 
63   echo "Your original zsh config was restored. Please restart your session."
64 else