install.sh 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. set -e
  2. # Use colors, but only if connected to a terminal, and that terminal
  3. # supports them.
  4. ncolors=$(tput colors)
  5. if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then
  6. RED="$(tput setaf 1)"
  7. GREEN="$(tput setaf 2)"
  8. YELLOW="$(tput setaf 3)"
  9. BLUE="$(tput setaf 4)"
  10. BOLD="$(tput bold)"
  11. NORMAL="$(tput sgr0)"
  12. else
  13. RED=""
  14. GREEN=""
  15. YELLOW=""
  16. BLUE=""
  17. BOLD=""
  18. NORMAL=""
  19. fi
  20. if [ ! -n "$ZSH" ]; then
  21. ZSH=~/.oh-my-zsh
  22. fi
  23. if [ -d "$ZSH" ]; then
  24. printf "${YELLOW}You already have Oh My Zsh installed.${NORMAL}\n"
  25. printf "You'll need to remove $ZSH if you want to re-install.\n"
  26. exit
  27. fi
  28. printf "${BLUE}Cloning Oh My Zsh...${NORMAL}\n"
  29. hash git >/dev/null 2>&1 && env git clone --depth=1 https://github.com/robbyrussell/oh-my-zsh.git $ZSH || {
  30. printf "git not installed\n"
  31. exit
  32. }
  33. printf "${BLUE}Looking for an existing zsh config...${NORMAL}\n"
  34. if [ -f ~/.zshrc ] || [ -h ~/.zshrc ]; then
  35. printf "${YELLOW}Found ~/.zshrc.${NORMAL} ${GREEN}Backing up to ~/.zshrc.pre-oh-my-zsh${NORMAL}\n";
  36. mv ~/.zshrc ~/.zshrc.pre-oh-my-zsh;
  37. fi
  38. printf "${BLUE}Using the Oh My Zsh template file and adding it to ~/.zshrc${NORMAL}\n"
  39. cp $ZSH/templates/zshrc.zsh-template ~/.zshrc
  40. sed -i -e "/^export ZSH=/ c\\
  41. export ZSH=$ZSH
  42. " ~/.zshrc
  43. printf "${BLUE}Copying your current PATH and adding it to the end of ~/.zshrc for you.${NORMAL}\n"
  44. sed -i -e "/export PATH=/ c\\
  45. export PATH=\"$PATH\"
  46. " ~/.zshrc
  47. TEST_CURRENT_SHELL=$(expr "$SHELL" : '.*/\(.*\)')
  48. if [ "$TEST_CURRENT_SHELL" != "zsh" ]; then
  49. printf "${BLUE}Time to change your default shell to zsh!${NORMAL}\n"
  50. chsh -s $(grep /zsh$ /etc/shells | tail -1)
  51. fi
  52. unset TEST_CURRENT_SHELL
  53. printf "${GREEN}"
  54. echo ' __ __ '
  55. echo ' ____ / /_ ____ ___ __ __ ____ _____/ /_ '
  56. echo ' / __ \/ __ \ / __ `__ \/ / / / /_ / / ___/ __ \ '
  57. echo '/ /_/ / / / / / / / / / / /_/ / / /_(__ ) / / / '
  58. echo '\____/_/ /_/ /_/ /_/ /_/\__, / /___/____/_/ /_/ '
  59. echo ' /____/ ....is now installed!'
  60. echo ''
  61. echo ''
  62. echo 'Please look over the ~/.zshrc file to select plugins, themes, and options.'
  63. echo ''
  64. echo 'p.s. Follow us at https://twitter.com/ohmyzsh.'
  65. echo ''
  66. echo 'p.p.s. Get stickers and t-shirts at http://shop.planetargon.com.'
  67. echo ''
  68. printf "${NORMAL}"
  69. env zsh