install.sh 18 KB

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