install.sh 3.28 KB
Newer Older
Andrew Vit's avatar
Andrew Vit committed
1
2
set -e

3
4
# Use colors, but only if connected to a terminal, and that terminal
# supports them.
5
6
7
8
tput=$(which tput)
if [ -n "$tput" ]; then
    ncolors=$($tput colors)
fi
9
if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then
10
  RED="$(tput setaf 1)"
11
12
13
14
15
16
17
18
19
20
21
22
23
  GREEN="$(tput setaf 2)"
  YELLOW="$(tput setaf 3)"
  BLUE="$(tput setaf 4)"
  BOLD="$(tput bold)"
  NORMAL="$(tput sgr0)"
else
  RED=""
  GREEN=""
  YELLOW=""
  BLUE=""
  BOLD=""
  NORMAL=""
fi
24
25
CHECK_ZSH_INSTALLED=$(grep /zsh$ /etc/shells | wc -l)
if [ ! $CHECK_ZSH_INSTALLED -ge 1 ]; then
26
  printf "${YELLOW}Zsh is not installed!${NORMAL} Please install zsh first!\n"
27
28
29
  exit
fi
unset CHECK_ZSH_INSTALLED
30

31
if [ ! -n "$ZSH" ]; then
32
33
34
  ZSH=~/.oh-my-zsh
fi

35
if [ -d "$ZSH" ]; then
36
37
  printf "${YELLOW}You already have Oh My Zsh installed.${NORMAL}\n"
  printf "You'll need to remove $ZSH if you want to re-install.\n"
Robby Russell's avatar
Robby Russell committed
38
39
40
  exit
fi

41
42
43
44
45
46
47
# Prevent the cloned repository from having insecure permissions. Failing to do
# so causes compinit() calls to fail with "command not found: compdef" errors
# for users with insecure umasks (e.g., "002", allowing group writability). Note
# that this will be ignored under Cygwin by default, as Windows ACLs take
# precedence over umasks except for filesystems mounted with option "noacl".
umask g-w,o-w

48
printf "${BLUE}Cloning Oh My Zsh...${NORMAL}\n"
49
hash git >/dev/null 2>&1 && env git clone --depth=1 https://github.com/robbyrussell/oh-my-zsh.git $ZSH || {
50
  printf "git not installed\n"
51
  exit
Renan Cakirerk's avatar
Renan Cakirerk committed
52
}
Toon Claes's avatar
Toon Claes committed
53

54
printf "${BLUE}Looking for an existing zsh config...${NORMAL}\n"
55
if [ -f ~/.zshrc ] || [ -h ~/.zshrc ]; then
56
  printf "${YELLOW}Found ~/.zshrc.${NORMAL} ${GREEN}Backing up to ~/.zshrc.pre-oh-my-zsh${NORMAL}\n";
57
  mv ~/.zshrc ~/.zshrc.pre-oh-my-zsh;
Robby Russell's avatar
Robby Russell committed
58
59
fi

60
printf "${BLUE}Using the Oh My Zsh template file and adding it to ~/.zshrc${NORMAL}\n"
61
cp $ZSH/templates/zshrc.zsh-template ~/.zshrc
62
sed "/^export ZSH=/ c\\
63
export ZSH=$ZSH
64
65
" ~/.zshrc > ~/.zshrc-omztemp
mv -f ~/.zshrc-omztemp ~/.zshrc
Robby Russell's avatar
Robby Russell committed
66

67
printf "${BLUE}Copying your current PATH and adding it to the end of ~/.zshrc for you.${NORMAL}\n"
68
sed "/export PATH=/ c\\
69
export PATH=\"$PATH\"
70
71
" ~/.zshrc > ~/.zshrc-omztemp
mv -f ~/.zshrc-omztemp ~/.zshrc
72

73
74
75
76
# If this user's login shell is not already "zsh", attempt to switch.
if [ "$(expr "$SHELL" : '.*/\(.*\)')" != "zsh" ]; then
  # If this platform provides a "chsh" command (not Cygwin), do it, man!
  if hash chsh >/dev/null 2>&1; then
77
    printf "${BLUE}Time to change your default shell to zsh!${NORMAL}\n"
78
    chsh -s $(grep /zsh$ /etc/shells | tail -1)
79
80
  # Else, suggest the user do so manually.
  else
81
    printf "${BLUE}Please manually change your default shell to zsh!${NORMAL}\n"
82
  fi
83
fi
Robby Russell's avatar
Robby Russell committed
84

85
86
87
88
89
90
91
92
93
94
95
printf "${GREEN}"
echo '         __                                     __   '
echo '  ____  / /_     ____ ___  __  __   ____  _____/ /_  '
echo ' / __ \/ __ \   / __ `__ \/ / / /  /_  / / ___/ __ \ '
echo '/ /_/ / / / /  / / / / / / /_/ /    / /_(__  ) / / / '
echo '\____/_/ /_/  /_/ /_/ /_/\__, /    /___/____/_/ /_/  '
echo '                        /____/                       ....is now installed!'
echo ''
echo ''
echo 'Please look over the ~/.zshrc file to select plugins, themes, and options.'
echo ''
96
echo 'p.s. Follow us at https://twitter.com/ohmyzsh.'
97
98
99
echo ''
echo 'p.p.s. Get stickers and t-shirts at http://shop.planetargon.com.'
echo ''
100
printf "${NORMAL}"
101
env zsh