install.sh 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  1. #!/bin/sh
  2. #
  3. # This script should be run via curl:
  4. # sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
  5. # or via wget:
  6. # sh -c "$(wget -qO- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
  7. # or via fetch:
  8. # sh -c "$(fetch -o - https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
  9. #
  10. # As an alternative, you can first download the install script and run it afterwards:
  11. # wget https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh
  12. # sh install.sh
  13. #
  14. # You can tweak the install behavior by setting variables when running the script. For
  15. # example, to change the path to the Oh My Zsh repository:
  16. # ZSH=~/.zsh sh install.sh
  17. #
  18. # Respects the following environment variables:
  19. # ZDOTDIR - path to Zsh dotfiles directory (default: unset). See [1][2]
  20. # [1] https://zsh.sourceforge.io/Doc/Release/Parameters.html#index-ZDOTDIR
  21. # [2] https://zsh.sourceforge.io/Doc/Release/Files.html#index-ZDOTDIR_002c-use-of
  22. # ZSH - path to the Oh My Zsh repository folder (default: $HOME/.oh-my-zsh)
  23. # REPO - name of the GitHub repo to install from (default: ohmyzsh/ohmyzsh)
  24. # REMOTE - full remote URL of the git repo to install (default: GitHub via HTTPS)
  25. # BRANCH - branch to check out immediately after install (default: master)
  26. #
  27. # Other options:
  28. # CHSH - 'no' means the installer will not change the default shell (default: yes)
  29. # RUNZSH - 'no' means the installer will not run zsh after the install (default: yes)
  30. # KEEP_ZSHRC - 'yes' means the installer will not replace an existing .zshrc (default: no)
  31. #
  32. # You can also pass some arguments to the install script to set some these options:
  33. # --skip-chsh: has the same behavior as setting CHSH to 'no'
  34. # --unattended: sets both CHSH and RUNZSH to 'no'
  35. # --keep-zshrc: sets KEEP_ZSHRC to 'yes'
  36. # For example:
  37. # sh install.sh --unattended
  38. # or:
  39. # sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended
  40. #
  41. set -e
  42. # Make sure important variables exist if not already defined
  43. #
  44. # $USER is defined by login(1) which is not always executed (e.g. containers)
  45. # POSIX: https://pubs.opengroup.org/onlinepubs/009695299/utilities/id.html
  46. USER=${USER:-$(id -u -n)}
  47. # $HOME is defined at the time of login, but it could be unset. If it is unset,
  48. # a tilde by itself (~) will not be expanded to the current user's home directory.
  49. # POSIX: https://pubs.opengroup.org/onlinepubs/009696899/basedefs/xbd_chap08.html#tag_08_03
  50. HOME="${HOME:-$(getent passwd $USER 2>/dev/null | cut -d: -f6)}"
  51. # macOS does not have getent, but this works even if $HOME is unset
  52. HOME="${HOME:-$(eval echo ~$USER)}"
  53. # Track if $ZSH was provided
  54. custom_zsh=${ZSH:+yes}
  55. # Use $zdot to keep track of where the directory is for zsh dotfiles
  56. # To check if $ZDOTDIR was provided, explicitly check for $ZDOTDIR
  57. zdot="${ZDOTDIR:-$HOME}"
  58. # Default value for $ZSH
  59. # a) if $ZDOTDIR is supplied and not $HOME: $ZDOTDIR/ohmyzsh
  60. # b) otherwise, $HOME/.oh-my-zsh
  61. if [ -n "$ZDOTDIR" ] && [ "$ZDOTDIR" != "$HOME" ]; then
  62. ZSH="${ZSH:-$ZDOTDIR/ohmyzsh}"
  63. fi
  64. ZSH="${ZSH:-$HOME/.oh-my-zsh}"
  65. # Default settings
  66. REPO=${REPO:-ohmyzsh/ohmyzsh}
  67. REMOTE=${REMOTE:-https://github.com/${REPO}.git}
  68. BRANCH=${BRANCH:-master}
  69. # Other options
  70. CHSH=${CHSH:-yes}
  71. RUNZSH=${RUNZSH:-yes}
  72. KEEP_ZSHRC=${KEEP_ZSHRC:-no}
  73. command_exists() {
  74. command -v "$@" >/dev/null 2>&1
  75. }
  76. user_can_sudo() {
  77. # Check if sudo is installed
  78. command_exists sudo || return 1
  79. # Termux can't run sudo, so we can detect it and exit the function early.
  80. case "$PREFIX" in
  81. *com.termux*) return 1 ;;
  82. esac
  83. # The following command has 3 parts:
  84. #
  85. # 1. Run `sudo` with `-v`. Does the following:
  86. # • with privilege: asks for a password immediately.
  87. # • without privilege: exits with error code 1 and prints the message:
  88. # Sorry, user <username> may not run sudo on <hostname>
  89. #
  90. # 2. Pass `-n` to `sudo` to tell it to not ask for a password. If the
  91. # password is not required, the command will finish with exit code 0.
  92. # If one is required, sudo will exit with error code 1 and print the
  93. # message:
  94. # sudo: a password is required
  95. #
  96. # 3. Check for the words "may not run sudo" in the output to really tell
  97. # whether the user has privileges or not. For that we have to make sure
  98. # to run `sudo` in the default locale (with `LANG=`) so that the message
  99. # stays consistent regardless of the user's locale.
  100. #
  101. ! LANG= sudo -n -v 2>&1 | grep -q "may not run sudo"
  102. }
  103. # The [ -t 1 ] check only works when the function is not called from
  104. # a subshell (like in `$(...)` or `(...)`, so this hack redefines the
  105. # function at the top level to always return false when stdout is not
  106. # a tty.
  107. if [ -t 1 ]; then
  108. is_tty() {
  109. true
  110. }
  111. else
  112. is_tty() {
  113. false
  114. }
  115. fi
  116. # This function uses the logic from supports-hyperlinks[1][2], which is
  117. # made by Kat Marchán (@zkat) and licensed under the Apache License 2.0.
  118. # [1] https://github.com/zkat/supports-hyperlinks
  119. # [2] https://crates.io/crates/supports-hyperlinks
  120. #
  121. # Copyright (c) 2021 Kat Marchán
  122. #
  123. # Licensed under the Apache License, Version 2.0 (the "License");
  124. # you may not use this file except in compliance with the License.
  125. # You may obtain a copy of the License at
  126. #
  127. # http://www.apache.org/licenses/LICENSE-2.0
  128. #
  129. # Unless required by applicable law or agreed to in writing, software
  130. # distributed under the License is distributed on an "AS IS" BASIS,
  131. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  132. # See the License for the specific language governing permissions and
  133. # limitations under the License.
  134. supports_hyperlinks() {
  135. # $FORCE_HYPERLINK must be set and be non-zero (this acts as a logic bypass)
  136. if [ -n "$FORCE_HYPERLINK" ]; then
  137. [ "$FORCE_HYPERLINK" != 0 ]
  138. return $?
  139. fi
  140. # If stdout is not a tty, it doesn't support hyperlinks
  141. is_tty || return 1
  142. # DomTerm terminal emulator (domterm.org)
  143. if [ -n "$DOMTERM" ]; then
  144. return 0
  145. fi
  146. # VTE-based terminals above v0.50 (Gnome Terminal, Guake, ROXTerm, etc)
  147. if [ -n "$VTE_VERSION" ]; then
  148. [ $VTE_VERSION -ge 5000 ]
  149. return $?
  150. fi
  151. # If $TERM_PROGRAM is set, these terminals support hyperlinks
  152. case "$TERM_PROGRAM" in
  153. Hyper|iTerm.app|terminology|WezTerm|vscode) return 0 ;;
  154. esac
  155. # These termcap entries support hyperlinks
  156. case "$TERM" in
  157. xterm-kitty|alacritty|alacritty-direct) return 0 ;;
  158. esac
  159. # xfce4-terminal supports hyperlinks
  160. if [ "$COLORTERM" = "xfce4-terminal" ]; then
  161. return 0
  162. fi
  163. # Windows Terminal also supports hyperlinks
  164. if [ -n "$WT_SESSION" ]; then
  165. return 0
  166. fi
  167. # Konsole supports hyperlinks, but it's an opt-in setting that can't be detected
  168. # https://github.com/ohmyzsh/ohmyzsh/issues/10964
  169. # if [ -n "$KONSOLE_VERSION" ]; then
  170. # return 0
  171. # fi
  172. return 1
  173. }
  174. # Adapted from code and information by Anton Kochkov (@XVilka)
  175. # Source: https://gist.github.com/XVilka/8346728
  176. supports_truecolor() {
  177. case "$COLORTERM" in
  178. truecolor|24bit) return 0 ;;
  179. esac
  180. case "$TERM" in
  181. iterm |\
  182. tmux-truecolor |\
  183. linux-truecolor |\
  184. xterm-truecolor |\
  185. screen-truecolor) return 0 ;;
  186. esac
  187. return 1
  188. }
  189. fmt_link() {
  190. # $1: text, $2: url, $3: fallback mode
  191. if supports_hyperlinks; then
  192. printf '\033]8;;%s\033\\%s\033]8;;\033\\\n' "$2" "$1"
  193. return
  194. fi
  195. case "$3" in
  196. --text) printf '%s\n' "$1" ;;
  197. --url|*) fmt_underline "$2" ;;
  198. esac
  199. }
  200. fmt_underline() {
  201. is_tty && printf '\033[4m%s\033[24m\n' "$*" || printf '%s\n' "$*"
  202. }
  203. # shellcheck disable=SC2016 # backtick in single-quote
  204. fmt_code() {
  205. is_tty && printf '`\033[2m%s\033[22m`\n' "$*" || printf '`%s`\n' "$*"
  206. }
  207. fmt_error() {
  208. printf '%sError: %s%s\n' "${FMT_BOLD}${FMT_RED}" "$*" "$FMT_RESET" >&2
  209. }
  210. setup_color() {
  211. # Only use colors if connected to a terminal
  212. if ! is_tty; then
  213. FMT_RAINBOW=""
  214. FMT_RED=""
  215. FMT_GREEN=""
  216. FMT_YELLOW=""
  217. FMT_BLUE=""
  218. FMT_BOLD=""
  219. FMT_RESET=""
  220. return
  221. fi
  222. if supports_truecolor; then
  223. FMT_RAINBOW="
  224. $(printf '\033[38;2;255;0;0m')
  225. $(printf '\033[38;2;255;97;0m')
  226. $(printf '\033[38;2;247;255;0m')
  227. $(printf '\033[38;2;0;255;30m')
  228. $(printf '\033[38;2;77;0;255m')
  229. $(printf '\033[38;2;168;0;255m')
  230. $(printf '\033[38;2;245;0;172m')
  231. "
  232. else
  233. FMT_RAINBOW="
  234. $(printf '\033[38;5;196m')
  235. $(printf '\033[38;5;202m')
  236. $(printf '\033[38;5;226m')
  237. $(printf '\033[38;5;082m')
  238. $(printf '\033[38;5;021m')
  239. $(printf '\033[38;5;093m')
  240. $(printf '\033[38;5;163m')
  241. "
  242. fi
  243. FMT_RED=$(printf '\033[31m')
  244. FMT_GREEN=$(printf '\033[32m')
  245. FMT_YELLOW=$(printf '\033[33m')
  246. FMT_BLUE=$(printf '\033[34m')
  247. FMT_BOLD=$(printf '\033[1m')
  248. FMT_RESET=$(printf '\033[0m')
  249. }
  250. setup_ohmyzsh() {
  251. # Prevent the cloned repository from having insecure permissions. Failing to do
  252. # so causes compinit() calls to fail with "command not found: compdef" errors
  253. # for users with insecure umasks (e.g., "002", allowing group writability). Note
  254. # that this will be ignored under Cygwin by default, as Windows ACLs take
  255. # precedence over umasks except for filesystems mounted with option "noacl".
  256. umask g-w,o-w
  257. echo "${FMT_BLUE}Cloning Oh My Zsh...${FMT_RESET}"
  258. command_exists git || {
  259. fmt_error "git is not installed"
  260. exit 1
  261. }
  262. ostype=$(uname)
  263. if [ -z "${ostype%CYGWIN*}" ] && git --version | grep -Eq 'msysgit|windows'; then
  264. fmt_error "Windows/MSYS Git is not supported on Cygwin"
  265. fmt_error "Make sure the Cygwin git package is installed and is first on the \$PATH"
  266. exit 1
  267. fi
  268. # Manual clone with git config options to support git < v1.7.2
  269. git init --quiet "$ZSH" && cd "$ZSH" \
  270. && git config core.eol lf \
  271. && git config core.autocrlf false \
  272. && git config fsck.zeroPaddedFilemode ignore \
  273. && git config fetch.fsck.zeroPaddedFilemode ignore \
  274. && git config receive.fsck.zeroPaddedFilemode ignore \
  275. && git config oh-my-zsh.remote origin \
  276. && git config oh-my-zsh.branch "$BRANCH" \
  277. && git remote add origin "$REMOTE" \
  278. && git fetch --depth=1 origin \
  279. && git checkout -b "$BRANCH" "origin/$BRANCH" || {
  280. [ ! -d "$ZSH" ] || {
  281. cd -
  282. rm -rf "$ZSH" 2>/dev/null
  283. }
  284. fmt_error "git clone of oh-my-zsh repo failed"
  285. exit 1
  286. }
  287. # Exit installation directory
  288. cd -
  289. echo
  290. }
  291. setup_zshrc() {
  292. # Keep most recent old .zshrc at .zshrc.pre-oh-my-zsh, and older ones
  293. # with datestamp of installation that moved them aside, so we never actually
  294. # destroy a user's original zshrc
  295. echo "${FMT_BLUE}Looking for an existing zsh config...${FMT_RESET}"
  296. # Must use this exact name so uninstall.sh can find it
  297. OLD_ZSHRC="$zdot/.zshrc.pre-oh-my-zsh"
  298. if [ -f "$zdot/.zshrc" ] || [ -h "$zdot/.zshrc" ]; then
  299. # Skip this if the user doesn't want to replace an existing .zshrc
  300. if [ "$KEEP_ZSHRC" = yes ]; then
  301. echo "${FMT_YELLOW}Found ${zdot}/.zshrc.${FMT_RESET} ${FMT_GREEN}Keeping...${FMT_RESET}"
  302. return
  303. fi
  304. if [ -e "$OLD_ZSHRC" ]; then
  305. OLD_OLD_ZSHRC="${OLD_ZSHRC}-$(date +%Y-%m-%d_%H-%M-%S)"
  306. if [ -e "$OLD_OLD_ZSHRC" ]; then
  307. fmt_error "$OLD_OLD_ZSHRC exists. Can't back up ${OLD_ZSHRC}"
  308. fmt_error "re-run the installer again in a couple of seconds"
  309. exit 1
  310. fi
  311. mv "$OLD_ZSHRC" "${OLD_OLD_ZSHRC}"
  312. echo "${FMT_YELLOW}Found old .zshrc.pre-oh-my-zsh." \
  313. "${FMT_GREEN}Backing up to ${OLD_OLD_ZSHRC}${FMT_RESET}"
  314. fi
  315. echo "${FMT_YELLOW}Found ${zdot}/.zshrc.${FMT_RESET} ${FMT_GREEN}Backing up to ${OLD_ZSHRC}${FMT_RESET}"
  316. mv "$zdot/.zshrc" "$OLD_ZSHRC"
  317. fi
  318. echo "${FMT_GREEN}Using the Oh My Zsh template file and adding it to $zdot/.zshrc.${FMT_RESET}"
  319. # Modify $ZSH variable in .zshrc directory to use the literal $ZDOTDIR or $HOME
  320. omz="$ZSH"
  321. if [ -n "$ZDOTDIR" ] && [ "$ZDOTDIR" != "$HOME" ]; then
  322. omz=$(echo "$omz" | sed "s|^$ZDOTDIR/|\$ZDOTDIR/|")
  323. fi
  324. omz=$(echo "$omz" | sed "s|^$HOME/|\$HOME/|")
  325. sed "s|^export ZSH=.*$|export ZSH=\"${omz}\"|" "$ZSH/templates/zshrc.zsh-template" > "$zdot/.zshrc-omztemp"
  326. mv -f "$zdot/.zshrc-omztemp" "$zdot/.zshrc"
  327. echo
  328. }
  329. setup_shell() {
  330. # Skip setup if the user wants or stdin is closed (not running interactively).
  331. if [ "$CHSH" = no ]; then
  332. return
  333. fi
  334. # If this user's login shell is already "zsh", do not attempt to switch.
  335. if [ "$(basename -- "$SHELL")" = "zsh" ]; then
  336. return
  337. fi
  338. # If this platform doesn't provide a "chsh" command, bail out.
  339. if ! command_exists chsh; then
  340. cat <<EOF
  341. I can't change your shell automatically because this system does not have chsh.
  342. ${FMT_BLUE}Please manually change your default shell to zsh${FMT_RESET}
  343. EOF
  344. return
  345. fi
  346. echo "${FMT_BLUE}Time to change your default shell to zsh:${FMT_RESET}"
  347. # Prompt for user choice on changing the default login shell
  348. printf '%sDo you want to change your default shell to zsh? [Y/n]%s ' \
  349. "$FMT_YELLOW" "$FMT_RESET"
  350. read -r opt
  351. case $opt in
  352. y*|Y*|"") ;;
  353. n*|N*) echo "Shell change skipped."; return ;;
  354. *) echo "Invalid choice. Shell change skipped."; return ;;
  355. esac
  356. # Check if we're running on Termux
  357. case "$PREFIX" in
  358. *com.termux*) termux=true; zsh=zsh ;;
  359. *) termux=false ;;
  360. esac
  361. if [ "$termux" != true ]; then
  362. # Test for the right location of the "shells" file
  363. if [ -f /etc/shells ]; then
  364. shells_file=/etc/shells
  365. elif [ -f /usr/share/defaults/etc/shells ]; then # Solus OS
  366. shells_file=/usr/share/defaults/etc/shells
  367. else
  368. fmt_error "could not find /etc/shells file. Change your default shell manually."
  369. return
  370. fi
  371. # Get the path to the right zsh binary
  372. # 1. Use the most preceding one based on $PATH, then check that it's in the shells file
  373. # 2. If that fails, get a zsh path from the shells file, then check it actually exists
  374. if ! zsh=$(command -v zsh) || ! grep -qx "$zsh" "$shells_file"; then
  375. if ! zsh=$(grep '^/.*/zsh$' "$shells_file" | tail -n 1) || [ ! -f "$zsh" ]; then
  376. fmt_error "no zsh binary found or not present in '$shells_file'"
  377. fmt_error "change your default shell manually."
  378. return
  379. fi
  380. fi
  381. fi
  382. # We're going to change the default shell, so back up the current one
  383. if [ -n "$SHELL" ]; then
  384. echo "$SHELL" > "$zdot/.shell.pre-oh-my-zsh"
  385. else
  386. grep "^$USER:" /etc/passwd | awk -F: '{print $7}' > "$zdot/.shell.pre-oh-my-zsh"
  387. fi
  388. echo "Changing your shell to $zsh..."
  389. # Check if user has sudo privileges to run `chsh` with or without `sudo`
  390. #
  391. # This allows the call to succeed without password on systems where the
  392. # user does not have a password but does have sudo privileges, like in
  393. # Google Cloud Shell.
  394. #
  395. # On systems that don't have a user with passwordless sudo, the user will
  396. # be prompted for the password either way, so this shouldn't cause any issues.
  397. #
  398. if user_can_sudo; then
  399. sudo -k chsh -s "$zsh" "$USER" # -k forces the password prompt
  400. else
  401. chsh -s "$zsh" "$USER" # run chsh normally
  402. fi
  403. # Check if the shell change was successful
  404. if [ $? -ne 0 ]; then
  405. fmt_error "chsh command unsuccessful. Change your default shell manually."
  406. else
  407. export SHELL="$zsh"
  408. echo "${FMT_GREEN}Shell successfully changed to '$zsh'.${FMT_RESET}"
  409. fi
  410. echo
  411. }
  412. # shellcheck disable=SC2183 # printf string has more %s than arguments ($FMT_RAINBOW expands to multiple arguments)
  413. print_success() {
  414. printf '%s %s__ %s %s %s %s %s__ %s\n' $FMT_RAINBOW $FMT_RESET
  415. printf '%s ____ %s/ /_ %s ____ ___ %s__ __ %s ____ %s_____%s/ /_ %s\n' $FMT_RAINBOW $FMT_RESET
  416. printf '%s / __ \\%s/ __ \\ %s / __ `__ \\%s/ / / / %s /_ / %s/ ___/%s __ \\ %s\n' $FMT_RAINBOW $FMT_RESET
  417. printf '%s/ /_/ /%s / / / %s / / / / / /%s /_/ / %s / /_%s(__ )%s / / / %s\n' $FMT_RAINBOW $FMT_RESET
  418. printf '%s\\____/%s_/ /_/ %s /_/ /_/ /_/%s\\__, / %s /___/%s____/%s_/ /_/ %s\n' $FMT_RAINBOW $FMT_RESET
  419. printf '%s %s %s %s /____/ %s %s %s %s....is now installed!%s\n' $FMT_RAINBOW $FMT_GREEN $FMT_RESET
  420. printf '\n'
  421. printf '\n'
  422. printf "%s %s %s\n" "Before you scream ${FMT_BOLD}${FMT_YELLOW}Oh My Zsh!${FMT_RESET} look over the" \
  423. "$(fmt_code "$(fmt_link ".zshrc" "file://$zdot/.zshrc" --text)")" \
  424. "file to select plugins, themes, and options."
  425. printf '\n'
  426. printf '%s\n' "• Follow us on Twitter: $(fmt_link @ohmyzsh https://twitter.com/ohmyzsh)"
  427. printf '%s\n' "• Join our Discord community: $(fmt_link "Discord server" https://discord.gg/ohmyzsh)"
  428. printf '%s\n' "• Get stickers, t-shirts, coffee mugs and more: $(fmt_link "Planet Argon Shop" https://shop.planetargon.com/collections/oh-my-zsh)"
  429. printf '%s\n' $FMT_RESET
  430. }
  431. main() {
  432. # Run as unattended if stdin is not a tty
  433. if [ ! -t 0 ]; then
  434. RUNZSH=no
  435. CHSH=no
  436. fi
  437. # Parse arguments
  438. while [ $# -gt 0 ]; do
  439. case $1 in
  440. --unattended) RUNZSH=no; CHSH=no ;;
  441. --skip-chsh) CHSH=no ;;
  442. --keep-zshrc) KEEP_ZSHRC=yes ;;
  443. esac
  444. shift
  445. done
  446. setup_color
  447. if ! command_exists zsh; then
  448. echo "${FMT_YELLOW}Zsh is not installed.${FMT_RESET} Please install zsh first."
  449. exit 1
  450. fi
  451. if [ -d "$ZSH" ]; then
  452. echo "${FMT_YELLOW}The \$ZSH folder already exists ($ZSH).${FMT_RESET}"
  453. if [ "$custom_zsh" = yes ]; then
  454. cat <<EOF
  455. You ran the installer with the \$ZSH setting or the \$ZSH variable is
  456. exported. You have 3 options:
  457. 1. Unset the ZSH variable when calling the installer:
  458. $(fmt_code "ZSH= sh install.sh")
  459. 2. Install Oh My Zsh to a directory that doesn't exist yet:
  460. $(fmt_code "ZSH=path/to/new/ohmyzsh/folder sh install.sh")
  461. 3. (Caution) If the folder doesn't contain important information,
  462. you can just remove it with $(fmt_code "rm -r $ZSH")
  463. EOF
  464. else
  465. echo "You'll need to remove it if you want to reinstall."
  466. fi
  467. exit 1
  468. fi
  469. # Create ZDOTDIR folder structure if it doesn't exist
  470. if [ -n "$ZDOTDIR" ]; then
  471. mkdir -p "$ZDOTDIR"
  472. fi
  473. setup_ohmyzsh
  474. setup_zshrc
  475. setup_shell
  476. print_success
  477. if [ $RUNZSH = no ]; then
  478. echo "${FMT_YELLOW}Run zsh to try it out.${FMT_RESET}"
  479. exit
  480. fi
  481. exec zsh -l
  482. }
  483. main "$@"