install.sh 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. CHECK_ZSH_INSTALLED=$(grep /zsh$ /etc/shells | wc -l)
  21. if [ ! $CHECK_ZSH_INSTALLED -ge 1 ]; then
  22. printf "${YELLOW}Zsh is not installed!${NORMAL} Please install zsh first!\n"
  23. exit
  24. fi
  25. unset CHECK_ZSH_INSTALLED
  26. if [ ! -n "$ZSH" ]; then
  27. ZSH=~/.oh-my-zsh
  28. fi
  29. if [ -d "$ZSH" ]; then
  30. printf "${YELLOW}You already have Oh My Zsh installed.${NORMAL}\n"
  31. printf "You'll need to remove $ZSH if you want to re-install.\n"
  32. exit
  33. fi
  34. # Prevent the cloned repository from having insecure permissions. Failing to do
  35. # so causes compinit() calls to fail with "command not found: compdef" errors
  36. # for users with insecure umasks (e.g., "002", allowing group writability). Note
  37. # that this will be ignored under Cygwin by default, as Windows ACLs take
  38. # precedence over umasks except for filesystems mounted with option "noacl".
  39. umask g-w,o-w
  40. printf "${BLUE}Cloning Oh My Zsh...${NORMAL}\n"
  41. hash git >/dev/null 2>&1 && env git clone --depth=1 https://github.com/robbyrussell/oh-my-zsh.git $ZSH || {
  42. printf "git not installed\n"
  43. exit
  44. }
  45. printf "${BLUE}Looking for an existing zsh config...${NORMAL}\n"
  46. if [ -f ~/.zshrc ] || [ -h ~/.zshrc ]; then
  47. printf "${YELLOW}Found ~/.zshrc.${NORMAL} ${GREEN}Backing up to ~/.zshrc.pre-oh-my-zsh${NORMAL}\n";
  48. mv ~/.zshrc ~/.zshrc.pre-oh-my-zsh;
  49. fi
  50. printf "${BLUE}Using the Oh My Zsh template file and adding it to ~/.zshrc${NORMAL}\n"
  51. cp $ZSH/templates/zshrc.zsh-template ~/.zshrc
  52. sed "/^export ZSH=/ c\\
  53. export ZSH=$ZSH
  54. " ~/.zshrc > ~/.zshrc-omztemp
  55. mv -f ~/.zshrc-omztemp ~/.zshrc
  56. printf "${BLUE}Copying your current PATH and adding it to the end of ~/.zshrc for you.${NORMAL}\n"
  57. sed "/export PATH=/ c\\
  58. export PATH=\"$PATH\"
  59. " ~/.zshrc > ~/.zshrc-omztemp
  60. mv -f ~/.zshrc-omztemp ~/.zshrc
  61. # If this user's login shell is not already "zsh", attempt to switch.
  62. if [ "$(expr "$SHELL" : '.*/\(.*\)')" != "zsh" ]; then
  63. # If this platform provides a "chsh" command (not Cygwin), do it, man!
  64. if hash chsh >/dev/null 2>&1; then
  65. printf "${BLUE}Time to change your default shell to zsh!${NORMAL}\n"
  66. chsh -s $(grep /zsh$ /etc/shells | tail -1)
  67. # Else, suggest the user do so manually.
  68. else
  69. printf "${BLUE}Please manually change your default shell to zsh!${NORMAL}\n"
  70. fi
  71. fi
  72. printf "${GREEN}"
  73. echo ' __ __ '
  74. echo ' ____ / /_ ____ ___ __ __ ____ _____/ /_ '
  75. echo ' / __ \/ __ \ / __ `__ \/ / / / /_ / / ___/ __ \ '
  76. echo '/ /_/ / / / / / / / / / / /_/ / / /_(__ ) / / / '
  77. echo '\____/_/ /_/ /_/ /_/ /_/\__, / /___/____/_/ /_/ '
  78. echo ' /____/ ....is now installed!'
  79. echo ''
  80. echo ''
  81. echo 'Please look over the ~/.zshrc file to select plugins, themes, and options.'
  82. echo ''
  83. echo 'p.s. Follow us at https://twitter.com/ohmyzsh.'
  84. echo ''
  85. echo 'p.p.s. Get stickers and t-shirts at http://shop.planetargon.com.'
  86. echo ''
  87. printf "${NORMAL}"
  88. env zsh