-
Notifications
You must be signed in to change notification settings - Fork 4
/
install.sh
executable file
·354 lines (310 loc) · 8.53 KB
/
install.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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
#!/bin/bash
set -e
# Utility functions
## For ease of iterative experimentation
doo () {
$@
# echo $@
}
command_exists () {
type "$1" &> /dev/null ;
}
is_osx () {
if [ "$(uname)" == "Darwin" ]; then
true
else
false
fi
}
installed () {
echo -e " ✓ $1 already installed."
}
# This function was originally named errm to be short for "error message", but
# then I realized that it sounds like a person saying, "Errm, excuse me, I don't
# think that's what you meant to do."
errm () {
2>&1 echo -e "$@"
}
# START HERE.
main () {
cd $HOME
install_zsh
install_rg
install_universal_ctags
setup_ctags
install_plug
install_tmux
install_tpm
install_tmuxinator
confirm_no_clobber
confirm_have_goodies
install_scm_breeze
install_diff-so-fancy
install_alacritty
install_fzf
for i in ${DOTS[@]}; do
link_dot $i
done
install_neovim
setup_git_global_ignore
setup_window_tiling
}
install_zsh() {
if !(command_exists zsh); then
doo apt-get install zsh --assume-yes
doo chsh -s /bin/zsh
else
installed 'zsh'
fi
# Install oh-my-zsh
DIR="/Users/$USER/.oh-my-zsh"
if [ ! -d "$DIR" ]; then
# https://github.com/ohmyzsh/ohmyzsh#unattended-install
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended
# Remove zshrc created by oh-my-zsh by default because we have our own
doo rm -rf ~/.zshrc
# Setup theme in oh-my-zsh
doo cp "$EXPORT_DIR/themes/clean-minimal.zsh-theme" ~/.oh-my-zsh/themes/clean-minimal.zsh-theme
# Install zsh-autosuggestions plugin
doo git clone https://github.com/zsh-users/zsh-autosuggestions ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions
else
installed 'oh-my-zsh'
fi
}
install_universal_ctags () {
if !(command_exists uctags); then
# requirements
if !(command_exists automake); then
doo brew install automake
fi
if !(command_exists pkg-config); then
doo brew install pkg-config
fi
if !(command_exists libxml2); then
doo brew install libxml2
fi
# Troubleshooting tips: If "error undefined macro AC_MSG_ERRO" error
# https://github.com/pooler/cpuminer/issues/74
# doo sudo apt-get install libcurl4-openssl-dev --assume-yes
doo git clone https://github.com/universal-ctags/ctags.git
doo cd ctags
doo ./autogen.sh
doo ./configure --program-prefix=u
doo make
# If fails for ex: in docker, try removing sudo
doo sudo make install
doo cd ..
doo rm -rf ctags
else
installed 'Universal-ctags'
fi
}
setup_ctags () {
SRC="git_template"
DEST=.$SRC
if [ ! -d ".$SRC" ]; then
git config --global init.templatedir '~/.git_template'
git config --global alias.ctags '!.git/hooks/ctags'
doo cp -R $EXPORT_DIR/$SRC $DEST
else
installed 'ctags git hooks'
fi
}
# ripgrep search, faster than ack, ag, silver surfer etc.
# Used by ctrlsf.vim plugin to do searching words in a project
install_rg () {
if !(command_exists rg); then
doo brew install ripgrep
else
installed 'rg'
fi
}
# Install plug for first time if .vim directory doesn't exist
install_plug() {
FILE=".vim/autoload/plug.vim"
if [ ! -f "$FILE" ]; then
doo curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
else
installed 'Plug'
fi
}
install_tmux () {
if !(command_exists tmux); then
doo brew install tmux
else
installed 'tmux'
fi
}
install_tpm() {
DIR=".tmux/plugins/tpm"
if [ ! -d "$DIR" ]; then
doo git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm && ~/.tmux/plugins/tpm/bin/install_plugins
else
installed 'TPM'
fi
}
install_tmuxinator () {
# Tmuxinator requires a higher ruby version
# Using rbenv to manage ruby version for the root directory
if !(command_exists rbenv); then
doo brew install rbenv
doo rbenv install 2.6.3
doo rbenv local 2.6.3
else
installed 'rbenv'
fi
if !(command_exists tmuxinator); then
doo sudo gem install tmuxinator
else
installed 'tmuxinator'
fi
}
# Subroutines
confirm_no_clobber() {
NOTADOT=''
for i in ${DOTS[@]}; do
dst=.$i
if [ ! -L $dst -a -e $dst ]; then
NOTADOT="${NOTADOT}$dst "
fi
done
if [ -n "$NOTADOT" ]; then
errm "\n ABORT"
errm "\n These exist but are not symlinks:"
errm " $NOTADOT"
exit 2
fi
}
confirm_have_goodies() {
NOFINDINGS=''
if [ ! -e "$EXPORT_DIR" ]; then
errm "\n ABORT\n\n Where ya gonna copy them files from again?"
errm " Couldn't find export dir: '$EXPORT_DIR'"
exit 2
fi
for i in ${DOTS[@]}; do
goody="$EXPORT_DIR/$i"
# Exists, is readable?
if [ ! -r "$goody" ]; then
NOFINDINGS="${NOFINDINGS}$i"
# Searchable if directory?
elif [ -d "$goody" -a ! -x "$goody" ]; then
NOFINDINGS="${NOFINDINGS}$i"
fi
done
if [ -n "$NOFINDINGS" ]; then
errm "\n ABORT\n\n These goodies don't exist in a state we can use!"
errm " $NOFINDINGS"
exit 2
fi
}
install_scm_breeze() {
DIR='scm_breeze'
if [ ! -d ".$DIR" ]; then
doo git clone https://github.com/scmbreeze/scm_breeze.git ~/.scm_breeze
doo ~/.scm_breeze/install.sh
else
installed 'scm_breeze'
fi
}
install_diff-so-fancy() {
if !(command_exists diff-so-fancy); then
doo brew install diff-so-fancy
git config --global core.pager "diff-so-fancy | less --tabs=4 -RFX"
git config --bool --global diff-so-fancy.markEmptyLines false
else
installed 'diff-so-fancy'
fi
}
install_neovim() {
if !(command_exists nvim); then
# TODO: Update this, Currently I just download the binary from neovim,
# put that in ~/Downloads/<here> & source it via ~/.zshrc
doo brew install neovim/neovim/neovim
doo ln -s ~/.vim ~/.config/nvim
doo ln -s ~/.vimrc ~/.config/nvim/init.vim
doo ln -s "$EXPORT_DIR/config/coc-settings.json" ~/.vim/coc-settings.json
doo pip3 install --user pynvim
doo ln -s "$EXPORT_DIR/lua" ~/.vim/lua
else
installed 'neovim'
fi
}
setup_window_tiling() {
# Setup tiling manager with yabai
if !(command_exists yabai); then
doo brew install koekeishiya/formulae/yabai
doo mkdir -p .config/yabai
doo ln -s "$EXPORT_DIR/config/yabairc" ~/.config/yabai/yabairc
doo yabai --start-service
else
installed 'yabai'
fi
# Setup shortcuts using skhd
if !(command_exists skhd); then
doo brew install skhd
doo mkdir -p .config/skhd
doo ln -s "$EXPORT_DIR/config/skhdrc" ~/.config/skhd/skhdrc
doo skhd --start-service
else
installed 'skhd'
fi
}
# https://github.com/alacritty/alacritty#macos
# Alacritty helpful links:
# Setup italics: https://alexpearce.me/2014/05/italics-in-iterm2-vim-tmux/
# Ligature for operator mono: https://github.com/kiliman/operator-mono-lig
install_alacritty() {
if !(command_exists alacritty); then
doo brew install alacritty --cask
# clone
doo git clone https://github.com/alacritty/alacritty.git
doo cd alacritty
# Not needed to be set anymore, seem to be working by default since 0.12 version
# https://github.com/alacritty/alacritty/blob/master/INSTALL.md#terminfo
# Install terminfo globally, I'm thinking this is to make the awesome
# true colors & italic fonts work
# We also change default terminal to alacritty in ~/.tmux.conf to use this
# doo sudo tic -xe alacritty,alacritty-direct extra/alacritty.info
# clean
doo cd ..
doo rm -rf alacritty
# Symlink config file
doo mkdir -p .config/alacritty
doo ln -s "$EXPORT_DIR/config/alacritty.yml" ~/.config/alacritty/alacritty.yml
# Enable smoothing on mac
doo defaults write -g CGFontRenderingFontSmoothingDisabled -bool NO
doo defaults -currentHost write -globalDomain AppleFontSmoothing -int 2
else
installed 'alacritty'
fi
}
install_fzf() {
if !(command_exists fzf); then
doo brew install fzf
else
installed 'fzf'
fi
}
link_dot() {
src=$1
dst=.$1
doo rm -f $dst
doo ln -s $EXPORT_DIR/$src $dst
}
setup_git_global_ignore() {
doo git config --global core.excludesfile ~/.gitignore_global
}
# Initialize globals
EXPORT_DIR=$(dirname "${PWD}/$0")
DOTS=(
vimrc
zshrc
tmux.conf
tmux-theme.conf
tern-config
ackrc
gitignore_global
)
# Fire missiles
main