cef64c465aa81b68fbbec5b008eeae1cb63805d3

Author
Carlo Sala <carlosalag@protonmail.com>
Committer
GitHub <noreply@github.com>
Date

Message

fix(install): ensure `--unattended` is respected (#13275)

Closes #13274

Diff

 1diff --git a/tools/install.sh b/tools/install.sh
 2index d274c2c9fa7bb61f6858fb811fda040026f4099b..8cf62a76ec4d2432bad2bdf9183fb13d2d607dee 100755
 3--- a/tools/install.sh
 4+++ b/tools/install.sh
 5@@ -25,9 +25,10 @@
 6 #   BRANCH  - branch to check out immediately after install (default: master)
 7 #
 8 # Other options:
 9-#   CHSH       - 'no' means the installer will not change the default shell (default: yes)
10-#   RUNZSH     - 'no' means the installer will not run zsh after the install (default: yes)
11-#   KEEP_ZSHRC - 'yes' means the installer will not replace an existing .zshrc (default: no)
12+#   CHSH                   - 'no' means the installer will not change the default shell (default: yes)
13+#   RUNZSH                 - 'no' means the installer will not run zsh after the install (default: yes)
14+#   KEEP_ZSHRC             - 'yes' means the installer will not replace an existing .zshrc (default: no)
15+#   OVERWRITE_CONFIRMATION - 'no' means the installer will not ask for confirmation to overwrite the existing .zshrc (default: yes)
16 #
17 # You can also pass some arguments to the install script to set some these options:
18 #   --skip-chsh: has the same behavior as setting CHSH to 'no'
19@@ -77,6 +78,7 @@ BRANCH=${BRANCH:-master}
20 CHSH=${CHSH:-yes}
21 RUNZSH=${RUNZSH:-yes}
22 KEEP_ZSHRC=${KEEP_ZSHRC:-no}
23+OVERWRITE_CONFIRMATION=${OVERWRITE_CONFIRMATION:-yes}
24 
25 
26 command_exists() {
27@@ -342,21 +344,23 @@ setup_zshrc() {
28       return
29     fi
30     
31-    # Ask user for confirmation before backing up and overwriting
32-    echo "${FMT_YELLOW}Found ${zdot}/.zshrc."
33-    echo "The existing .zshrc will be backed up to .zshrc.pre-oh-my-zsh if overwritten."
34-    echo "Make sure your .zshrc contains the following minimal configuration if you choose not to overwrite it:${FMT_RESET}"
35-    echo "----------------------------------------"
36-    cat "$ZSH/templates/minimal.zshrc"
37-    echo "----------------------------------------"
38-    printf '%sDo you want to overwrite it with the Oh My Zsh template? [Y/n]%s ' \
39-      "$FMT_YELLOW" "$FMT_RESET"
40-    read -r opt
41-    case $opt in
42-      [Yy]*|"") ;;
43-      [Nn]*) echo "Overwrite skipped. Existing .zshrc will be kept."; return ;;
44-      *) echo "Invalid choice. Overwrite skipped. Existing .zshrc will be kept."; return ;;
45-    esac
46+    if [ $OVERWRITE_CONFIRMATION != "no" ]; then
47+      # Ask user for confirmation before backing up and overwriting
48+      echo "${FMT_YELLOW}Found ${zdot}/.zshrc."
49+      echo "The existing .zshrc will be backed up to .zshrc.pre-oh-my-zsh if overwritten."
50+      echo "Make sure your .zshrc contains the following minimal configuration if you choose not to overwrite it:${FMT_RESET}"
51+      echo "----------------------------------------"
52+      cat "$ZSH/templates/minimal.zshrc"
53+      echo "----------------------------------------"
54+      printf '%sDo you want to overwrite it with the Oh My Zsh template? [Y/n]%s ' \
55+        "$FMT_YELLOW" "$FMT_RESET"
56+      read -r opt
57+      case $opt in
58+        [Yy]*|"") ;;
59+        [Nn]*) echo "Overwrite skipped. Existing .zshrc will be kept."; return ;;
60+        *) echo "Invalid choice. Overwrite skipped. Existing .zshrc will be kept."; return ;;
61+      esac
62+    fi
63 
64     if [ -e "$OLD_ZSHRC" ]; then
65       OLD_OLD_ZSHRC="${OLD_ZSHRC}-$(date +%Y-%m-%d_%H-%M-%S)"
66@@ -510,12 +514,13 @@ main() {
67   if [ ! -t 0 ]; then
68     RUNZSH=no
69     CHSH=no
70+    OVERWRITE_CONFIRMATION=no
71   fi
72 
73   # Parse arguments
74   while [ $# -gt 0 ]; do
75     case $1 in
76-      --unattended) RUNZSH=no; CHSH=no ;;
77+      --unattended) RUNZSH=no; CHSH=no; OVERWRITE_CONFIRMATION=no ;;
78       --skip-chsh) CHSH=no ;;
79       --keep-zshrc) KEEP_ZSHRC=yes ;;
80     esac