1
0
mirror of https://github.com/robbyrussell/oh-my-zsh.git synced 2025-12-06 07:20:40 +01:00

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

Closes #13274
This commit is contained in:
Carlo Sala
2025-08-19 12:46:13 +02:00
committed by GitHub
parent c2a69fe590
commit cef64c465a

View File

@@ -25,9 +25,10 @@
# BRANCH - branch to check out immediately after install (default: master) # BRANCH - branch to check out immediately after install (default: master)
# #
# Other options: # Other options:
# CHSH - 'no' means the installer will not change the default shell (default: yes) # CHSH - 'no' means the installer will not change the default shell (default: yes)
# RUNZSH - 'no' means the installer will not run zsh after the install (default: yes) # RUNZSH - 'no' means the installer will not run zsh after the install (default: yes)
# KEEP_ZSHRC - 'yes' means the installer will not replace an existing .zshrc (default: no) # KEEP_ZSHRC - 'yes' means the installer will not replace an existing .zshrc (default: no)
# OVERWRITE_CONFIRMATION - 'no' means the installer will not ask for confirmation to overwrite the existing .zshrc (default: yes)
# #
# You can also pass some arguments to the install script to set some these options: # You can also pass some arguments to the install script to set some these options:
# --skip-chsh: has the same behavior as setting CHSH to 'no' # --skip-chsh: has the same behavior as setting CHSH to 'no'
@@ -77,6 +78,7 @@ BRANCH=${BRANCH:-master}
CHSH=${CHSH:-yes} CHSH=${CHSH:-yes}
RUNZSH=${RUNZSH:-yes} RUNZSH=${RUNZSH:-yes}
KEEP_ZSHRC=${KEEP_ZSHRC:-no} KEEP_ZSHRC=${KEEP_ZSHRC:-no}
OVERWRITE_CONFIRMATION=${OVERWRITE_CONFIRMATION:-yes}
command_exists() { command_exists() {
@@ -342,21 +344,23 @@ setup_zshrc() {
return return
fi fi
# Ask user for confirmation before backing up and overwriting if [ $OVERWRITE_CONFIRMATION != "no" ]; then
echo "${FMT_YELLOW}Found ${zdot}/.zshrc." # Ask user for confirmation before backing up and overwriting
echo "The existing .zshrc will be backed up to .zshrc.pre-oh-my-zsh if overwritten." echo "${FMT_YELLOW}Found ${zdot}/.zshrc."
echo "Make sure your .zshrc contains the following minimal configuration if you choose not to overwrite it:${FMT_RESET}" echo "The existing .zshrc will be backed up to .zshrc.pre-oh-my-zsh if overwritten."
echo "----------------------------------------" echo "Make sure your .zshrc contains the following minimal configuration if you choose not to overwrite it:${FMT_RESET}"
cat "$ZSH/templates/minimal.zshrc" echo "----------------------------------------"
echo "----------------------------------------" cat "$ZSH/templates/minimal.zshrc"
printf '%sDo you want to overwrite it with the Oh My Zsh template? [Y/n]%s ' \ echo "----------------------------------------"
"$FMT_YELLOW" "$FMT_RESET" printf '%sDo you want to overwrite it with the Oh My Zsh template? [Y/n]%s ' \
read -r opt "$FMT_YELLOW" "$FMT_RESET"
case $opt in read -r opt
[Yy]*|"") ;; case $opt in
[Nn]*) echo "Overwrite skipped. Existing .zshrc will be kept."; return ;; [Yy]*|"") ;;
*) echo "Invalid choice. Overwrite skipped. Existing .zshrc will be kept."; return ;; [Nn]*) echo "Overwrite skipped. Existing .zshrc will be kept."; return ;;
esac *) echo "Invalid choice. Overwrite skipped. Existing .zshrc will be kept."; return ;;
esac
fi
if [ -e "$OLD_ZSHRC" ]; then if [ -e "$OLD_ZSHRC" ]; then
OLD_OLD_ZSHRC="${OLD_ZSHRC}-$(date +%Y-%m-%d_%H-%M-%S)" OLD_OLD_ZSHRC="${OLD_ZSHRC}-$(date +%Y-%m-%d_%H-%M-%S)"
@@ -510,12 +514,13 @@ main() {
if [ ! -t 0 ]; then if [ ! -t 0 ]; then
RUNZSH=no RUNZSH=no
CHSH=no CHSH=no
OVERWRITE_CONFIRMATION=no
fi fi
# Parse arguments # Parse arguments
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
case $1 in case $1 in
--unattended) RUNZSH=no; CHSH=no ;; --unattended) RUNZSH=no; CHSH=no; OVERWRITE_CONFIRMATION=no ;;
--skip-chsh) CHSH=no ;; --skip-chsh) CHSH=no ;;
--keep-zshrc) KEEP_ZSHRC=yes ;; --keep-zshrc) KEEP_ZSHRC=yes ;;
esac esac