-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_zsh.sh
178 lines (158 loc) · 5.08 KB
/
install_zsh.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# Use colors, but only if connected to a terminal, and that terminal
# supports them.
if type tput > /dev/null; then
ncolors=$(tput colors)
fi
if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then
RED="$(tput setaf 1)"
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
REPO_URL="https://github.com/staskjs/dotfiles.git"
VIM_REPO_URL="https://github.com/staskjs/vimsettings.git"
if [ ! -n "$DOTFILES_VIM" ]; then
DOTFILES_VIM=1
fi
OMZ_INSTALLED=0
# Check if oh-my-zsh is installed. If not, then install it.
if [ ! -d ~/.oh-my-zsh ]; then
echo "Installing oh my zsh"
git clone -q https://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh
OMZ_INSTALLED=1
fi
# Install or update powerlevel9k zsh theme
if [ -d ~/.oh-my-zsh/custom/themes/powerlevel9k ]; then
echo "Powerlevel9k is installed - updating"
git -C ~/.oh-my-zsh/custom/themes/powerlevel9k pull > /dev/null
else
echo "Powerlevel9k theme is not installed - installing"
git clone -q https://github.com/bhilburn/powerlevel9k.git ~/.oh-my-zsh/custom/themes/powerlevel9k
fi
echo "Installing my zsh theme"
if [ -d ~/.oh-my-zsh/custom/themes/my-theme ]; then
rm ~/.oh-my-zsh/custom/themes/my-theme
fi
ln -s $DOTFILES/my-theme ~/.oh-my-zsh/custom/themes/
if [ ! -n "$DOTFILES" ]; then
export DOTFILES="$HOME/.dotfiles"
fi
# Clone or update dotfiles directory
if [ ! -d "$DOTFILES" ]; then
echo "Installing dotfiles in $DOTFILES"
git clone -q $REPO_URL $DOTFILES
else
CHANGED=$(git -C $DOTFILES diff-index --name-only HEAD --)
if [ -n "$CHANGED" ]; then
echo "${RED}$DOTFILES has changes. Commit (use \`dotpush\` command) or discard them and try again.${NORMAL}"
exit 1
else
echo "Updating dotfiles"
git -C $DOTFILES pull > /dev/null
fi
fi
if [ ! -n "$ZSH_CUSTOM" ]; then
ZSH_CUSTOM="$ZSH/custom"
fi
# Copy functions file to zsh_custom directory
if [ -f $ZSH_CUSTOM/functions.zsh ]; then
rm $ZSH_CUSTOM/functions.zsh
fi
ln -s $DOTFILES/functions.zsh $ZSH_CUSTOM/functions.zsh
# ---------------------------------------------------
# Copy .zshrc to home directory
echo "Installing .zshrc"
if [ -f ~/.zshrc ]; then
rm ~/.zshrc
fi
ln -s $DOTFILES/zshrc ~/.zshrc
# ---------------------------------------------------
# Copy .tmux.conf to home directory
echo "Installing .tmux.conf"
if [ -f ~/.tmux.conf ]; then
rm ~/.tmux.conf
fi
ln -s $DOTFILES/tmux.conf ~/.tmux.conf
# ---------------------------------------------------
# Copy git config files to home directory
echo "Installing git config"
if [ -f ~/.gitconfig ]; then
rm ~/.gitconfig
fi
ln -s $DOTFILES/gitconfig ~/.gitconfig
if [ -f ~/.gitmessage ]; then
rm ~/.gitmessage
fi
ln -s $DOTFILES/gitmessage ~/.gitmessage
if [ -f ~/.gitignore ]; then
rm ~/.gitignore
fi
ln -s $DOTFILES/gitignore ~/.gitignore
# ---------------------------------------------------
# Copy .tmux.conf to home directory
echo "Installing .irbrc"
if [ -f ~/.irbrc ]; then
rm ~/.irbrc
fi
ln -s $DOTFILES/irbrc ~/.irbrc
# ---------------------------------------------------
echo "Installing w3m keymap"
if [ -f ~/.w3m/keymap ]; then
rm ~/.w3m/keymap
fi
ln -s $DOTFILES/w3m-keymap ~/.w3m/keymap
# ---------------------------------------------------
# Install or update vim
if [ "$DOTFILES_VIM" -eq 1 ]; then
if [ -d ~/.vim ]; then
CHANGED=$(git -C ~/.vim diff-index --name-only HEAD --)
if [ -n "$CHANGED" ]; then
echo "${RED}~/.vim has changes. Commit (use \`vimpush\` command) or discard them and try again.${NORMAL}"
exit 1
else
echo "Updating vim"
git -C ~/.vim pull > /dev/null
if [ ! -f ~/.vim/bundle/Vundle.vim ]; then
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
fi
fi
else
echo "Installing vim settings"
git clone -q $VIM_REPO_URL ~/.vim
fi
# Copy vimrc file
if [ -f ~/.vimrc ]; then
rm ~/.vimrc
fi
ln -s ~/.vim/vimrc ~/.vimrc
fi
# Switch to zsh finally
TEST_CURRENT_SHELL=$(expr "$SHELL" : '.*/\(.*\)')
if [ "$TEST_CURRENT_SHELL" != "zsh" ]; then
# If this platform provides a "chsh" command (not Cygwin), do it, man!
if hash chsh >/dev/null 2>&1; then
chsh -s $(grep /zsh$ /etc/shells | tail -1)
# Else, suggest the user do so manually.
else
printf "I can't change your shell automatically because this system does not have chsh.\n"
printf "Please manually change your default shell to zsh!\n"
fi
fi
echo "${GREEN}"
echo "Everything is installed successfully!"
if [ "$OMZ_INSTALLED" -eq 1 ]; then
echo "Feel free to explore oh-my-zsh on https://github.com/robbyrussell/oh-my-zsh"
fi
echo "${BLUE}Use ~/.zshrc.custom file (create if not exists) to keep all custom configuration for current machine there."
echo "~/.zshrc should not contain any custom configuration, because it will be overriden on next update."
echo "${NORMAL}"
env zsh