install.sh 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. env git clone --depth=1 https://github.com/robbyrussell/oh-my-zsh.git $ZSH || {
  51. printf "Error: git clone of oh-my-zsh repo failed\n"
  52. exit 1
  53. }
  54. # The Windows (MSYS) Git is not compatible with normal use on cygwin
  55. if [ "$OSTYPE" = cygwin ]; then
  56. if git --version | grep msysgit > /dev/null; then
  57. echo "Error: Windows/MSYS Git is not supported on Cygwin"
  58. echo "Error: Make sure the Cygwin git package is installed and is first on the path"
  59. exit 1
  60. fi
  61. fi
  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. printf "${BLUE}Copying your current PATH and adding it to the end of ~/.zshrc for you.${NORMAL}\n"
  74. sed "/export PATH=/ c\\
  75. export PATH=\"$PATH\"
  76. " ~/.zshrc > ~/.zshrc-omztemp
  77. mv -f ~/.zshrc-omztemp ~/.zshrc
  78. # If this user's login shell is not already "zsh", attempt to switch.
  79. TEST_CURRENT_SHELL=$(expr "$SHELL" : '.*/\(.*\)')
  80. if [ "$TEST_CURRENT_SHELL" != "zsh" ]; then
  81. # If this platform provides a "chsh" command (not Cygwin), do it, man!
  82. if hash chsh >/dev/null 2>&1; then
  83. printf "${BLUE}Time to change your default shell to zsh!${NORMAL}\n"
  84. chsh -s $(grep /zsh$ /etc/shells | tail -1)
  85. # Else, suggest the user do so manually.
  86. else
  87. printf "I can't change your shell automatically because this system does not have chsh.\n"
  88. printf "${BLUE}Please manually change your default shell to zsh!${NORMAL}\n"
  89. fi
  90. fi
  91. printf "${GREEN}"
  92. echo ' __ __ '
  93. echo ' ____ / /_ ____ ___ __ __ ____ _____/ /_ '
  94. echo ' / __ \/ __ \ / __ `__ \/ / / / /_ / / ___/ __ \ '
  95. echo '/ /_/ / / / / / / / / / / /_/ / / /_(__ ) / / / '
  96. echo '\____/_/ /_/ /_/ /_/ /_/\__, / /___/____/_/ /_/ '
  97. echo ' /____/ ....is now installed!'
  98. echo ''
  99. echo ''
  100. echo 'Please look over the ~/.zshrc file to select plugins, themes, and options.'
  101. echo ''
  102. echo 'p.s. Follow us at https://twitter.com/ohmyzsh.'
  103. echo ''
  104. echo 'p.p.s. Get stickers and t-shirts at http://shop.planetargon.com.'
  105. echo ''
  106. printf "${NORMAL}"
  107. env zsh
  108. }
  109. main