-
Notifications
You must be signed in to change notification settings - Fork 2
/
create_dotfiles_etc
executable file
·218 lines (193 loc) · 6.45 KB
/
create_dotfiles_etc
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#!/bin/bash
if source ~/dotfiles/colorize.sh &>/dev/null ; then
:
else
echo "~/dotfiles/colorize.sh absent? Continue without color..."
echo
for func in red green yellow blue bold
do
eval "$func () { cat - ; }"
done
fi
if [[ ! -d "${HOME}/dotfiles" ]] ; then
echo "Create this repo as $HOME/dotfiles" | red
echo "Run the following command in your \$HOME:"
echo "cd ~ ; git clone https://github.com/ashayh/dotfiles.git"
echo "Exiting..."
exit 1
else
REPO=$(cd ~/dotfiles; git config --get remote.origin.url 2>/dev/null)
if [[ ${REPO} != *ashayh/dotfiles* ]] ; then
echo "~/dotfiles/ is not a git repo or a wrong repo." | red
echo "Follow instructions at: https://github.com/ashayh/dotfiles"
echo "Exiting..."
exit 1
fi
fi
DATE=$(date '+%d-%m-%y-%H-%M-%S')
# These are the commands we will check if present:
CMDS=(zsh hg curl wget vim unzip)
# These are the dirs we will create if absent:
MAKE_DIRS=(${HOME}/bin ${HOME}/.vim/backup ${HOME}/.vim/tmp ${HOME}/.tmux/plugins ${HOME}/.git/git-templates/hooks)
# These are the dotfiles we create as links ~/:
DOTFILES=(.gitconfig .irbrc .tmux.conf .vimrc .zshrc)
# These are the oh-my-zsh customizations,
# which end up in ~/.oh-my-zsh/custom/ :
OH_MY_FILES=(aliases.zsh ashay.zsh-theme)
# These are the oh-my-zsh plugin repos to clone:
OH_MY_PLUGINS=(zsh-users/zsh-syntax-highlighting zsh-users/zsh-history-substring-search)
# These are the files for ~/bin
# Includes this shell script :
BIN_FILES=(create_dotfiles_etc)
for cmd in ${CMDS[*]}
do
# Only care if present in \$PATH
if which ${cmd} &> /dev/null ; then
echo "${cmd} is present at $(which ${cmd})" | green
else
echo "${cmd} is absent or not in \$PATH. Exiting..." | red
exit 1
fi
done
echo
if [[ -d ${HOME}/.vim && ! -f ${HOME}/.vim/.ashay_dotfiles ]] ; then
echo "\${HOME}/.vim exists but was not created by this script: \${HOME}/.vim/.ashay_dotfiles is absent?" | yellow | bold
echo "Moving ${HOME}/.vim to /tmp/dot_vim.${DATE}" | yellow | bold
mv ${HOME}/.vim /tmp/dot_vim.${DATE}
echo "Copy /tmp/dot_vim.${DATE} back to your \$HOME to restore old vim config." | yellow | bold
else
echo "\${HOME}/.vim exists and was created by this script: \${HOME}/.vim/.ashay_dotfiles is present" | blue | bold
fi
echo
echo "Making ${HOME}/.vim only if absent..." | green | bold
[[ ! -d $HOME/.vim ]] && mkdir ${HOME}/.vim
touch ${HOME}/.vim/.ashay_dotfiles
for dir in ${MAKE_DIRS[*]}
do
if [[ ! -d ${dir} ]] ; then
echo "Creating ${dir} as it is absent..." | blue | bold
mkdir -p ${dir}
fi
done
echo
# Install oh-my-zsh
if [[ -d ${HOME}/.oh-my-zsh ]] ; then
REPO=$(cd ~/.oh-my-zsh ; git config --get remote.origin.url 2>/dev/null)
if [[ ${REPO} != *robbyrussell/oh-my-zsh.git ]] ; then
echo "${HOME}/.oh-my-zsh exists, but is not a git repo, or wrong repo." | red
echo "Install from: https://github.com/robbyrussell/oh-my-zsh.git"
echo "Exiting..."
exit 1
else
echo "${HOME}/.oh-my-zsh is the correct git repo (github.com/robbyrussell)." | white | bold
fi
else
echo "Installing oh-my-zsh..."
curl -L https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh | sh
fi
echo
for PLUG in ${OH_MY_PLUGINS[*]}
do
# Don't need github username for this comparison.
PLU_NAME=${PLUG#*/}
if [[ -d ${HOME}/.oh-my-zsh/plugins/${PLU_NAME} ]] ; then
echo "${HOME}/.oh-my-zsh/plugins/${PLU_NAME} exists already, trying next." | green
continue
else
echo "git cloning ${PLUG}"
{
cd ${HOME}/.oh-my-zsh/plugins/ ;
git clone git://github.com/${PLUG} ;
}
if [[ $? -ne 0 ]] ; then
echo "Error when git cloning git://github.com/${PLUG}" | red
fi
fi
done
echo
# Link ${HOME}/dotfiles files to ${HOME}/bin
for file in ${BIN_FILES[*]}
do
[[ ! -x ${HOME}/dotfiles/${file} ]] && chmod +x ${HOME}/dotfiles/${file}
IL=$(readlink ${HOME}/bin/${file})
if [[ ${IL} != "${HOME}/dotfiles/${file}" ]] ; then
echo "${IL} ${HOME}/bin/${file} "
echo "Creating ${HOME}/bin/${file} as link to ${HOME}/dotfiles/${file}" | blue | bold
if [[ -f ${HOME}/bin/${file} ]] ; then
mv ${HOME}/bin/${file} /tmp/${file}.${DATE}
echo "moved ${HOME}/bin/${file} to /tmp/${file}.${DATE}" | yellow
fi
echo
ln -s ${HOME}/dotfiles/${file} ${HOME}/bin/${file}
else
echo "${HOME}/bin/${file} is already ${IL}" | green
fi
IL=''
done
echo
# copy dot files to ${HOME}/
for file in ${DOTFILES[*]}
do
IL=$(readlink ${HOME}/${file})
if [[ ${IL} != "${HOME}/dotfiles/${file}" ]] ; then
echo "Creating ${HOME}/${file} as link to ${HOME}/dotfiles/${file}" | blue | bold
if [[ -f ${HOME}/${file} ]] ; then
mv ${HOME}/${file} /tmp/${file}.${DATE}
echo "moved ${HOME}/${file} to /tmp/${file}.${DATE}" | yellow
fi
ln -s ${HOME}/dotfiles/${file} ${HOME}/${file}
else
echo "${file} is already ${IL}" | green
fi
IL=''
done
echo
# copy files zsh theme and alias
for file in ${OH_MY_FILES[*]}
do
IL=$(readlink ${HOME}/.oh-my-zsh/custom/${file})
if [[ ${IL} != "${HOME}/dotfiles/.${file}" ]] ; then
echo "Creating ${HOME}/.oh-my-zsh/custom/${file} as link to ${HOME}/dotfiles/.${file}" | blue | bold
if [[ -f ${HOME}/.oh-my-zsh/custom/${file} ]] ; then
mv ${HOME}/.oh-my-zsh/custom/${file} /tmp/${file}.${DATE}
echo "moved ${HOME}/${file} to /tmp/${file}.${DATE}" | yellow
fi
ln -s ${HOME}/dotfiles/.${file} ${HOME}/.oh-my-zsh/custom/${file}
else
echo "${HOME}/.oh-my-zsh/custom/${file} is already ${IL}" | green
fi
IL=''
done
IL=$(readlink ${HOME}/.fzf.zsh)
if [[ ${IL} == "${HOME}/dotfiles/.fzf.zsh" ]] ; then
:
else
rm -f ~/.fzf.zsh
ln -s ~/dotfiles/.fzf.zsh ~/.fzf.zsh
fi
cp ~/dotfiles/diff-highlight ~/.git/
set -e
# TMUX plugins:
if [[ -d ~/.tmux/plugins/tpm/.git ]] ; then
echo "~/.tmux/plugins/tpm/.git exists" | green
else
echo "cloning ~/.tmux/plugins/tpm/ ..." | green
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
fi
mkdir -p ~/.vim/plugged
cd ~/.vim/plugged
if [[ -d YouCompleteMe/.git ]] ; then
echo "~/.vim/plugged/YouCompleteMe/.git exists" | green
else
echo "cloning ~/.vim/plugged/YouCompleteMe/ ..." | green
git clone https://github.com/Valloric/YouCompleteMe.git
cd YouCompleteMe/
git submodule update --init --recursive
echo "compiling youcompleteme libraries..." | green
./install.py --clang-completer
fi
set +e
cd
echo "All done." | green | bold
echo "After vim is run for the first time and plugins are cloned, Run ~/dotfiles/fixes.sh:" | green | bold
# ~/dotfiles/fixes.sh