installer: add option to install without replacing .zshrc (#8209)
* Add option to install OMZ without replacing .zshrc
tools/install.sh respects REPLACE_RC environment variable
--noreplace-rc flag sets REPLACE_RC='no'
* Change REPLACE_RC=no to KEEP_ZSHRC=yes
Change --noreplace-rc to --keep-zshrc
Diff
1diff --git a/tools/install.sh b/tools/install.sh
2index bdf9f18e9a16fb6cff4252ca20a78ae8285e11a7..08f3db1e329d9abe7f7df13e58c71770ebf4989c 100755
3--- a/tools/install.sh
4+++ b/tools/install.sh
5@@ -20,12 +20,14 @@
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+# CHSH - 'no' means the installer will not change the default shell (default: yes)
12+# RUNZSH - 'no' means the installer will not run zsh after the install (default: yes)
13+# KEEP_ZSHRC - 'yes' means the installer will not replace an existing .zshrc (default: no)
14 #
15 # You can also pass some arguments to the install script to set some these options:
16 # --skip-chsh: has the same behavior as setting CHSH to 'no'
17 # --unattended: sets both CHSH and RUNZSH to 'no'
18+# --keep-zshrc: sets KEEP_ZSHRC to 'yes'
19 # For example:
20 # sh install.sh --unattended
21 #
22@@ -40,6 +42,7 @@ BRANCH=${BRANCH:-master}
23 # Other options
24 CHSH=${CHSH:-yes}
25 RUNZSH=${RUNZSH:-yes}
26+KEEP_ZSHRC=${KEEP_ZSHRC:-no}
272829 command_exists() {
30@@ -111,6 +114,11 @@ setup_zshrc() {
31 # Must use this exact name so uninstall.sh can find it
32 OLD_ZSHRC=~/.zshrc.pre-oh-my-zsh
33 if [ -f ~/.zshrc ] || [ -h ~/.zshrc ]; then
34+ # Skip this if the user doesn't want to replace an existing .zshrc
35+ if [ $KEEP_ZSHRC = yes ]; then
36+ echo "${YELLOW}Found ~/.zshrc.${RESET} ${GREEN}Keeping...${RESET}"
37+ return
38+ fi
39 if [ -e "$OLD_ZSHRC" ]; then
40 OLD_OLD_ZSHRC="${OLD_ZSHRC}-$(date +%Y-%m-%d_%H-%M-%S)"
41 if [ -e "$OLD_OLD_ZSHRC" ]; then
42@@ -227,6 +235,7 @@ main() {
43 case $1 in
44 --unattended) RUNZSH=no; CHSH=no ;;
45 --skip-chsh) CHSH=no ;;
46+ --keep-zshrc) KEEP_ZSHRC=yes ;;
47 esac
48 shift
49 done