forked from jlong/tilde
/
setup.sh
executable file
·325 lines (247 loc) · 6.37 KB
/
setup.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
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
#!/bin/bash
SCRIPT=$(cd `dirname "${BASH_SOURCE[0]}"` && pwd)/`basename "${BASH_SOURCE[0]}"`
SCRIPTPATH=`dirname $SCRIPT`
PROFILE=$HOME/.bashrc
OHMYZSH=$HOME/.oh-my-zsh
ZSHRC=$HOME/.zshrc
HELP="
Usage:
$0 all # Install all the things
$0 all -tmux # Everything but Tmux
$0 +tmux # Just install Tmux
Description:
Wire in everything needed for my home directory. If parameters are
included, only wire in specific sections.
Options:
--profile path, -p path
The profile file to append to. (Default: $PROFILE)
Components:
Specific components can be turned on or off with a +/- prefix.
vim Vim config and plugins
git Git config
brew Homebrew
screen Screen config
tmux Tmux and Tmuxinator config
ack Ack config
irb IRB completion and other goodies
rake Rake completion
jshint JSHint config
bash Bash extras
zsh Zshell extras
bin Bin files
"
case $# in 0) echo "$HELP"; exit 0;; esac
# Parse options
while true
do
case $# in 0) break;; esac
case $1 in
--profile|-p)
shift;
PROFILE=$1
;;
all)
vim=true;
git=true;
brew=true;
screen=true;
tmux=true;
ack=true;
irb=true;
rake=true;
jshint=true;
bash=true;
bin=true;
zsh=true;
;;
+vim) vim=true;;
-vim) vim=false;;
+git) git=true;;
-git) git=false;;
+brew) brew=true;;
-brew) brew=false;;
+screen) screen=true;;
-screen) screen=false;;
+tmux) tmux=true;;
-tmux) tmux=false;;
+ack) ack=true;;
-ack) ack=false;;
+irb) irb=true;;
-irb) irb=false;;
+rake) rake=true;;
-rake) rake=false;;
+jshint) jshint=true;;
-jshint) jshint=false;;
+bash) bash=true;;
-bash) bash=false;;
+zsh) zsh=true;;
-zsh) zsh=false;;
+bin) bin=true;;
-bin) bin=true;;
help) echo "$HELP"; exit 0 ;;
*) echo; echo "Invalid option $1."; echo "$HELP"; exit 2 ;;
esac
shift
done
if [ "$git" = true ]; then
#######################
echo "Git"
#######################
update_profile=true
# A couple of things for Git that we want to be user global. Note that we
# should NOT link .git and .gitmodules as these belong to this project and are
# not intended to be in my user directory.
ln -sfv $SCRIPTPATH/.gitconfig $HOME/.gitconfig
ln -sfv $SCRIPTPATH/.gitignore $HOME/.gitignore
ln -sfv $SCRIPTPATH/.gitusers $HOME/.gitusers
ln -sfv $SCRIPTPATH/.git-completion $HOME/.git-completion
echo ""
fi
if [ "$brew" = true ]; then
#######################
echo "Homebrew"
#######################
if [[ ! -d /opt/homebrew/Cellar ]] && [[ ! -d /usr/local/Cellar ]]; then
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
echo ""
fi
if [ "$vim" = true ]; then
#######################
echo "Vim"
ln -sv $SCRIPTPATH/.vim/ $HOME/.vim
ln -sfv $SCRIPTPATH/.vimrc $HOME/.vimrc
ln -sfv $SCRIPTPATH/.gvimrc $HOME/.gvimrc
mkdir $SCRIPTPATH/.vim-tmp
# Install plugins
vim +PlugInstall +qall
echo ""
fi
if [ "$screen" = true ]; then
#######################
echo "Screen"
#######################
ln -sfv $SCRIPTPATH/.screenrc $HOME/.screenrc
echo ""
fi
if [ "$tmux" = true ]; then
#######################
echo "tmux"
#######################
update_profile=true
brew install tmuxinator
brew install reattach-to-user-namespace
ln -sfv $SCRIPTPATH/.tmux.conf $HOME/.tmux.conf
ln -sv $SCRIPTPATH/tmuxinator $HOME/.tmuxinator
ln -sfv $SCRIPTPATH/.tmux-completion $HOME/.tmux-completion
ln -sfv $SCRIPTPATH/.tmuxinator-completion $HOME/.tmuxinator-completion
echo ""
fi
if [ "$ack" = true ]; then
#######################
echo "ACK"
#######################
ln -sfv $SCRIPTPATH/.ackrc $HOME/.ackrc
echo ""
fi
if [ "$irb" = true ]; then
#######################
echo "IRB"
#######################
ln -sfv $SCRIPTPATH/.irbrc $HOME/.irbrc
echo ""
fi
if [ "$rake" = true ]; then
#######################
echo "Rake"
#######################
update_profile=true
mkdir $HOME/lib
ln -sfv $SCRIPTPATH/lib/rake-complete.rb $HOME/lib/rake-complete.rb
echo ""
fi
if [ "$jshint" = true ]; then
#######################
echo "JSHint"
#######################
npm install -g jshint
ln -sfv $SCRIPTPATH/.jshintrc $HOME/.jshintrc
echo ""
fi
add_to_profile() {
local line=$1
touch $PROFILE
if ! grep -q "$line" $PROFILE; then
echo " $line"
eval $(echo "$line" | tee -a $PROFILE)
fi
}
if [ "$bash" = true ]; then
#######################
echo "Bash Extras"
#######################
update_profile=true
ln -sfv $SCRIPTPATH/.prompt $HOME/.prompt
ln -sfv $SCRIPTPATH/.exports $HOME/.exports
ln -sfv $SCRIPTPATH/.aliases $HOME/.aliases
ln -sfv $SCRIPTPATH/.projects $HOME/.projects
ln -sfv $SCRIPTPATH/.brew-completion $HOME/.brew-completion
echo ""
fi
add_to_zshrc() {
local line=$1
touch $ZSHRC
if ! grep -q "$line" $ZSHRC; then
echo " $line"
eval $(echo "$line" | tee -a $ZSHRC)
fi
}
if [ "$zsh" = true ]; then
#######################
echo "Zshell Extras"
#######################
update_zshrc=true
if [[ ! -d "$OHMYZSH" ]]; then
echo "Installing Oh My Zsh..."
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
fi
echo ""
fi
if [ "$bin" = true ]; then
#######################
echo "Bin files"
#######################
ln -sfv $SCRIPTPATH/bin $HOME
fi
if [ "$update_profile" = true ]; then
echo ""
echo "Adding the following lines to your profile ($PROFILE):"
echo ""
if [ "$bash" = true ]; then
add_to_profile 'source ~/.prompt'
add_to_profile 'source ~/.exports'
add_to_profile 'source ~/.aliases'
add_to_profile 'source ~/.projects'
fi
if [ "$git" = true ]; then
add_to_profile 'source ~/.git-completion'
fi
if [ "$tmux" = true ]; then
add_to_profile 'source ~/.tmux-completion'
add_to_profile 'source ~/.tmuxinator-completion'
fi
if [ "$rake" = true ]; then
add_to_profile 'complete -C path/to/tilde/lib/rake-complete.rb -o default rake'
fi
add_to_profile 'source ~/.brew-completion'
fi
if [ "$update_zshrc" = true ]; then
echo ""
echo "Adding the following lines to your zshrc ($ZSHRC):"
echo ""
if [ "$zsh" = true ]; then
add_to_zshrc 'source ~/.aliases'
add_to_zshrc 'source ~/.projects'
fi
fi
echo ""