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

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

28
if [ ! -n "$ZSH" ]; then
29
30
31
  ZSH=~/.oh-my-zsh
fi

32
if [ -d "$ZSH" ]; then
33
34
  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
35
36
37
  exit
fi

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

44
printf "${BLUE}Looking for an existing zsh config...${NORMAL}\n"
45
if [ -f ~/.zshrc ] || [ -h ~/.zshrc ]; then
46
  printf "${YELLOW}Found ~/.zshrc.${NORMAL} ${GREEN}Backing up to ~/.zshrc.pre-oh-my-zsh${NORMAL}\n";
47
  mv ~/.zshrc ~/.zshrc.pre-oh-my-zsh;
Robby Russell's avatar
Robby Russell committed
48
49
fi

50
printf "${BLUE}Using the Oh My Zsh template file and adding it to ~/.zshrc${NORMAL}\n"
51
cp $ZSH/templates/zshrc.zsh-template ~/.zshrc
52
sed "/^export ZSH=/ c\\
53
export ZSH=$ZSH
54
55
" ~/.zshrc > ~/.zshrc-omztemp
mv -f ~/.zshrc-omztemp ~/.zshrc
Robby Russell's avatar
Robby Russell committed
56

57
printf "${BLUE}Copying your current PATH and adding it to the end of ~/.zshrc for you.${NORMAL}\n"
58
sed "/export PATH=/ c\\
59
export PATH=\"$PATH\"
60
61
" ~/.zshrc > ~/.zshrc-omztemp
mv -f ~/.zshrc-omztemp ~/.zshrc
62

63
64
TEST_CURRENT_SHELL=$(expr "$SHELL" : '.*/\(.*\)')
if [ "$TEST_CURRENT_SHELL" != "zsh" ]; then
65
    printf "${BLUE}Time to change your default shell to zsh!${NORMAL}\n"
66
    chsh -s $(grep /zsh$ /etc/shells | tail -1)
67
fi
68
unset TEST_CURRENT_SHELL
Robby Russell's avatar
Robby Russell committed
69

70
71
72
73
74
75
76
77
78
79
80
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 ''
81
echo 'p.s. Follow us at https://twitter.com/ohmyzsh.'
82
83
84
echo ''
echo 'p.p.s. Get stickers and t-shirts at http://shop.planetargon.com.'
echo ''
85
printf "${NORMAL}"
86
env zsh