install.sh 3.8 KB

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