Commit ad96cd85ef0e0b41e178ad42408cb8dc57420896

Authored by mj
Exists in master and in 2 other branches 02-merge, dev

Showing 116 changed files Side-by-side Diff

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