install.sh 3.8 KB

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