-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
ยท275 lines (213 loc) ยท 4.31 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
#!/bin/bash
# TODO
# - Install bash-sneak
set -eo pipefail
DOTFILES=(
bashrc
bashrc.d
bash_aliases
bash_profile
blerc
gitconfig
gitconfig.clio
gitignore
gitmessage
vimrc
vim
ackrc
inputrc
colordiffrc
ignore
tmux.conf
tmux
bin
tmuxinator
lftprc
pryrc
irbrc
config/alacritty
config/karabiner
config/nvim
config/coc/extensions/package.json
config/coc/extensions/yarn.lock
config/gh/config.yml
rbenv/version
)
LINUX_DOTFILES=(
Xmodmap
)
RCPATH="$HOME/Code/rc"
is_linux() {
[[ $(uname) == "Linux" ]]
}
is_mac() {
[[ $(uname) == "Darwin" ]]
}
is_windows() {
[[ $(uname) == MINGW.* ]]
}
get_src() {
case "$file" in
bashrc)
if is_windows; then
echo "$RCPATH/bashrc_msys"
exit
fi
;;
esac
echo "$RCPATH/$file"
}
get_dest() {
local file="$1"
case "$file" in
vim)
if is_windows; then
echo "$HOME/vimfiles"
exit
fi
;;
bin)
echo "$HOME/bin"
exit
;;
esac
echo "$HOME/.$file";
}
command_exists() {
command -v "$1" >/dev/null 2>&1
}
readlink_f() {
# https://stackoverflow.com/a/24572274/1333402
perl -MCwd -le 'print Cwd::abs_path shift' "$1"
}
install_fonts() {
if ! is_mac; then
return
fi
echo "๐พ Installing fonts..."
cp "${RCPATH}"/fonts/* /Library/Fonts
}
link_dotfiles() {
local src dest
local all_files=( "${DOTFILES[@]}" )
echo "๐พ Linking dotfiles..."
if is_linux; then
all_files+=( "${LINUX_DOTFILES[@]}" )
fi
for file in "${all_files[@]}"; do
src=$(get_src "$file")
dest=$(get_dest "$file")
orig_bk="${dest}.orig"
if [[ -L $dest ]]; then
if [[ $(readlink_f "$dest") == "$src" ]]; then
echo "Already installed $file"
continue
else
echo "Bad link location for $file, backing up to $orig_bk"
mv "$dest" "$orig_bk"
fi
elif [[ -e $dest ]]; then
echo "File already exists for $file, backing up to $orig_bk"
mv "$dest" "$orig_bk"
fi
echo "Installing $file"
install_file "$src" "$dest"
done
}
install_file() {
local src="$1"
local dest="$2"
if is_windows; then
rm -rf "$dest"
cp -r "$src" "$dest"
else
mkdir -p "$(dirname "$dest")"
ln -ns "$src" "$dest"
fi
}
install_vim_plugins() {
echo "๐พ Installing VIM Plugins..."
[[ -e ~/.venv/bin/pip ]] && ~/.venv/bin/pip install pynvim
command_exists gem && gem install neovim
command_exists npm && npm install -g neovim
command_exists nvim && nvim --headless +PlugInstall +qall
}
chsh_bash() {
local shell="/usr/bin/bash"
echo "๐พ Changing shell to BASH..."
if is_mac; then
shell="$(brew --prefix)/bin/bash"
grep -q "$shell" /etc/shells || sudo tee -a /etc/shells <<<"$shell" >/dev/null
fi
sudo chsh -s "$shell" "$USER"
}
install_homebrew() {
local prefix
if ! is_mac; then
return
fi
echo "๐พ Installing Homebrew..."
if [[ -e /opt/homebrew ]]; then
prefix=/opt/homebrew
else
prefix=/usr/local
fi
if ! [[ -e ${prefix}/bin/brew ]]; then
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
else
echo "๐พ ...Homebrew already exists!"
fi
# shellcheck source=/dev/null
eval "$($prefix/bin/brew shellenv)"
}
install_self() {
if [[ -e $RCPATH/install.sh ]]; then
return
fi
echo "๐พ Installing self..."
mkdir -p "$(dirname "$RCPATH")"
git clone https://github.com/shanesmith/dotfiles.git "$RCPATH"
}
install_brew_bundle() {
if ! is_mac; then
return
fi
echo "๐พ Installing Brew Bundles..."
brew bundle install
}
install_ruby() {
echo "๐พ Installing Ruby..."
rbenv install --skip-existing $(cat $RCPATH/rbenv/version)
eval "$(rbenv init -)"
}
install_python_venv() {
echo "๐พ Installing Python VENV..."
python3 -m venv ~/.venv
}
create_ssh_dir() {
echo "๐พ Creating ssh dir..."
mkdir -p ~/.ssh
chmod 700 ~/.ssh
}
set_preferences() {
if ! is_mac; then
return
fi
echo "๐พ Setting macOS Preferences..."
"$RCPATH"/mac-prefs.sh
}
# install homebrew before self so that it
# also installs xclt for git
install_homebrew
install_self
cd "$RCPATH"
install_brew_bundle
install_fonts
link_dotfiles
install_ruby
install_python_venv
install_vim_plugins
create_ssh_dir
chsh_bash
set_preferences
echo "๐พ DONE! ๐พ"