install.sh 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #!/bin/sh
  2. #
  3. # This script should be run via curl:
  4. # sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
  5. # or wget:
  6. # sh -c "$(wget -qO- https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
  7. #
  8. # As an alternative, you can download the install script separately and
  9. # run it afterwards with `sh install.sh'
  10. #
  11. set -e
  12. # Default location
  13. ZSH=${ZSH:-~/.oh-my-zsh}
  14. command_exists() {
  15. command -v "$@" >/dev/null 2>&1
  16. }
  17. main() {
  18. # Use colors, but only if connected to a terminal, and that terminal
  19. # supports them.
  20. if command_exists tput; then
  21. ncolors=$(tput colors)
  22. fi
  23. if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then
  24. RED="$(tput setaf 1)"
  25. GREEN="$(tput setaf 2)"
  26. YELLOW="$(tput setaf 3)"
  27. BLUE="$(tput setaf 4)"
  28. BOLD="$(tput bold)"
  29. NORMAL="$(tput sgr0)"
  30. else
  31. RED=""
  32. GREEN=""
  33. YELLOW=""
  34. BLUE=""
  35. BOLD=""
  36. NORMAL=""
  37. fi
  38. if ! command_exists zsh; then
  39. echo "${YELLOW}Zsh is not installed!${NORMAL} Please install zsh first!"
  40. exit 1
  41. fi
  42. if [ -d "$ZSH" ]; then
  43. cat <<-EOF
  44. ${YELLOW}You already have Oh My Zsh installed.${NORMAL}
  45. You'll need to remove $ZSH if you want to re-install.
  46. EOF
  47. exit 1
  48. fi
  49. # Prevent the cloned repository from having insecure permissions. Failing to do
  50. # so causes compinit() calls to fail with "command not found: compdef" errors
  51. # for users with insecure umasks (e.g., "002", allowing group writability). Note
  52. # that this will be ignored under Cygwin by default, as Windows ACLs take
  53. # precedence over umasks except for filesystems mounted with option "noacl".
  54. umask g-w,o-w
  55. echo "${BLUE}Cloning Oh My Zsh...${NORMAL}"
  56. command_exists git || {
  57. echo "Error: git is not installed"
  58. exit 1
  59. }
  60. if [ "$OSTYPE" = cygwin ] && git --version | grep -q msysgit; then
  61. cat <<-EOF
  62. Error: Windows/MSYS Git is not supported on Cygwin
  63. Error: Make sure the Cygwin git package is installed and is first on the $PATH
  64. EOF
  65. exit 1
  66. fi
  67. git clone --depth=1 https://github.com/robbyrussell/oh-my-zsh.git "$ZSH" || {
  68. echo "Error: git clone of oh-my-zsh repo failed"
  69. exit 1
  70. }
  71. echo "${BLUE}Looking for an existing zsh config...${NORMAL}"
  72. if [ -f ~/.zshrc ] || [ -h ~/.zshrc ]; then
  73. echo "${YELLOW}Found ~/.zshrc.${GREEN} Backing up to ~/.zshrc.pre-oh-my-zsh.${NORMAL}"
  74. mv ~/.zshrc ~/.zshrc.pre-oh-my-zsh;
  75. fi
  76. echo "${BLUE}Using the Oh My Zsh template file and adding it to ~/.zshrc.${NORMAL}"
  77. cp "$ZSH/templates/zshrc.zsh-template" ~/.zshrc
  78. sed "/^export ZSH=/ c\\
  79. export ZSH=\"$ZSH\"
  80. " ~/.zshrc > ~/.zshrc-omztemp
  81. mv -f ~/.zshrc-omztemp ~/.zshrc
  82. # If this user's login shell is not already "zsh", attempt to switch.
  83. TEST_CURRENT_SHELL=$(basename "$SHELL")
  84. if [ "$TEST_CURRENT_SHELL" != "zsh" ]; then
  85. # If this platform provides a "chsh" command (not Cygwin), do it, man!
  86. if command_exists chsh; then
  87. echo "${BLUE}Time to change your default shell to zsh!${NORMAL}"
  88. chsh -s $(grep /zsh$ /etc/shells | tail -1)
  89. # Else, suggest the user do so manually.
  90. else
  91. cat <<-EOF
  92. I can't change your shell automatically because this system does not have chsh.
  93. ${BLUE}Please manually change your default shell to zsh${NORMAL}
  94. EOF
  95. fi
  96. fi
  97. printf "$GREEN"
  98. cat <<-'EOF'
  99. __ __
  100. ____ / /_ ____ ___ __ __ ____ _____/ /_
  101. / __ \/ __ \ / __ `__ \/ / / / /_ / / ___/ __ \
  102. / /_/ / / / / / / / / / / /_/ / / /_(__ ) / / /
  103. \____/_/ /_/ /_/ /_/ /_/\__, / /___/____/_/ /_/
  104. /____/ ....is now installed!
  105. Please look over the ~/.zshrc file to select plugins, themes, and options.
  106. p.s. Follow us on https://twitter.com/ohmyzsh
  107. p.p.s. Get stickers, shirts, and coffee mugs at https://shop.planetargon.com/collections/oh-my-zsh
  108. EOF
  109. printf "$NORMAL"
  110. env zsh -l
  111. }
  112. main