install.sh 3.9 KB

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