install.sh 3.8 KB

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