feat(installer): add confirmation before overwriting existing .zshrc (#13086)
Diff
1diff --git a/tools/install.sh b/tools/install.sh
2index 5c9b2c18dc5fd48b1ccbd75224e86a053dec7c05..d274c2c9fa7bb61f6858fb811fda040026f4099b 100755
3--- a/tools/install.sh
4+++ b/tools/install.sh
5@@ -341,6 +341,23 @@ setup_zshrc() {
6 echo "${FMT_YELLOW}Found ${zdot}/.zshrc.${FMT_RESET} ${FMT_GREEN}Keeping...${FMT_RESET}"
7 return
8 fi
9+
10+ # Ask user for confirmation before backing up and overwriting
11+ echo "${FMT_YELLOW}Found ${zdot}/.zshrc."
12+ echo "The existing .zshrc will be backed up to .zshrc.pre-oh-my-zsh if overwritten."
13+ echo "Make sure your .zshrc contains the following minimal configuration if you choose not to overwrite it:${FMT_RESET}"
14+ echo "----------------------------------------"
15+ cat "$ZSH/templates/minimal.zshrc"
16+ echo "----------------------------------------"
17+ printf '%sDo you want to overwrite it with the Oh My Zsh template? [Y/n]%s ' \
18+ "$FMT_YELLOW" "$FMT_RESET"
19+ read -r opt
20+ case $opt in
21+ [Yy]*|"") ;;
22+ [Nn]*) echo "Overwrite skipped. Existing .zshrc will be kept."; return ;;
23+ *) echo "Invalid choice. Overwrite skipped. Existing .zshrc will be kept."; return ;;
24+ esac
25+
26 if [ -e "$OLD_ZSHRC" ]; then
27 OLD_OLD_ZSHRC="${OLD_ZSHRC}-$(date +%Y-%m-%d_%H-%M-%S)"
28 if [ -e "$OLD_OLD_ZSHRC" ]; then
29@@ -353,7 +370,7 @@ setup_zshrc() {
30 echo "${FMT_YELLOW}Found old .zshrc.pre-oh-my-zsh." \
31 "${FMT_GREEN}Backing up to ${OLD_OLD_ZSHRC}${FMT_RESET}"
32 fi
33- echo "${FMT_YELLOW}Found ${zdot}/.zshrc.${FMT_RESET} ${FMT_GREEN}Backing up to ${OLD_ZSHRC}${FMT_RESET}"
34+ echo "${FMT_GREEN}Backing up to ${OLD_ZSHRC}${FMT_RESET}"
35 mv "$zdot/.zshrc" "$OLD_ZSHRC"
36 fi
37