forked from thoughtbot/laptop
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathmac
402 lines (314 loc) · 9.67 KB
/
mac
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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
#!/bin/bash
# Welcome to the Nimble laptop script!
# Be prepared to turn your laptop (or desktop, no haters here)
# into an awesome development machine.
# shellcheck disable=SC2154
trap 'ret=$?; test $ret -ne 0 && printf "failed\n\n" >&2; exit $ret' EXIT
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
set -e
fancy_echo() {
local fmt="$1"; shift
# shellcheck disable=SC2059
printf "\n$fmt\n" "$@"
}
pre_setup() {
if [ ! -d "$HOME/.bin/" ]; then
mkdir "$HOME/.bin"
fi
if [ ! -f "$HOME/.zshrc" ]; then
touch "$HOME/.zshrc"
fi
if [ ! -f "$HOME/.Brewfile" ]; then
touch "$HOME/.Brewfile"
fi
# shellcheck disable=SC2016
append_to_zshrc 'export PATH="$HOME/.bin:$PATH"'
# Determine Homebrew prefix
ARCH="$(uname -m)"
if [ "$ARCH" = "arm64" ]; then
HOMEBREW_PREFIX="/opt/homebrew"
else
HOMEBREW_PREFIX="/usr/local"
fi
}
append_to_zshrc() {
local text="$1" zshrc
local skip_new_line="${2:-0}"
if [ -w "$HOME/.zshrc.local" ]; then
zshrc="$HOME/.zshrc.local"
else
zshrc="$HOME/.zshrc"
fi
if ! grep -Fqs "$text" "$zshrc"; then
if [ "$skip_new_line" -eq 1 ]; then
printf "%s\n" "$text" >> "$zshrc"
else
printf "\n%s\n" "$text" >> "$zshrc"
fi
fi
}
prepend_to_zshrc() {
local text="$1" zshrc
if [ -w "$HOME/.zshrc.local" ]; then
zshrc="$HOME/.zshrc.local"
else
zshrc="$HOME/.zshrc"
fi
echo -e "$text\n\n$(cat $zshrc)" > $zshrc
}
config_zsh() {
read -r -p "Do you want to install Zsh's extensions? [Y|n] " response
if [[ ! $response =~ (n|no|N) ]];then
sudo chsh -s $(which zsh)
fancy_echo "Installing Oh my Zsh"
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)" "" --unattended
if [ ! -d ~/.zsh/zsh-defer ]; then
git clone https://github.com/romkatv/zsh-defer.git ~/.zsh/zsh-defer
prepend_to_zshrc 'source ~/.zsh/zsh-defer/zsh-defer.plugin.zsh'
fi
if [ ! -d ~/.zsh/zsh-autosuggestions ]; then
git clone https://github.com/zsh-users/zsh-autosuggestions.git ~/.zsh/zsh-autosuggestions
prepend_to_zshrc 'source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh'
fi
if [ ! -d ~/.zsh/zsh-syntax-highlighting ]; then
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ~/.zsh/zsh-syntax-highlighting
prepend_to_zshrc 'source ~/.zsh/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh'
fi
if [ ! -d ~/.oh-my-zsh/custom/plugins/zsh-completions ]; then
git clone https://github.com/zsh-users/zsh-completions.git ~/.oh-my-zsh/custom/plugins/zsh-completions
prepend_to_zshrc 'fpath+=~/.oh-my-zsh/custom/plugins/zsh-completions/src'
fi
prepend_to_zshrc 'ZSH_DISABLE_COMPFIX=true'
# shellcheck disable=SC2016
append_to_zshrc 'export PATH="$HOME/.bin:$PATH"'
zsh_config_homebrew
# shellcheck disable=SC2016
append_to_zshrc 'export PATH=~/.asdf/shims:$PATH'
fancy_echo "Configured Zsh"
fi
}
gem_install_or_update() {
if gem list "$1" --installed > /dev/null; then
gem update "$@"
else
gem install "$@"
fi
}
install_homebrew() {
if ! command -v brew >/dev/null; then
fancy_echo "Installing Homebrew ..."
/bin/bash -c \
"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
zsh_config_homebrew
export PATH="$HOMEBREW_PREFIX/bin:$PATH"
fi
if brew list | grep -Fq brew-cask; then
fancy_echo "Uninstalling old Homebrew-Cask ..."
brew uninstall --force brew-cask
fi
}
zsh_config_homebrew() {
fancy_echo "Adding brew to zshrc automatically..."
append_to_zshrc "eval \"\$($HOMEBREW_PREFIX/bin/brew shellenv)\""
}
install_asdf() {
fancy_echo "Configuring asdf version manager ..."
if [ ! -d "$HOME/.asdf" ]; then
brew install asdf
# shellcheck disable=SC2016
append_to_zshrc 'export PATH=~/.asdf/shims:$PATH'
append_to_zshrc "source $(brew --prefix asdf)/libexec/asdf.sh" 1
fi
}
add_or_update_asdf_plugin() {
local name="$1"
local url="$2"
if ! asdf plugin-list | grep -Fq "$name"; then
asdf plugin-add "$name" "$url"
else
asdf plugin-update "$name"
fi
}
install_asdf_language() {
local language="$1"
local regex_pattern="$2"
local version
if [ -z "$regex_pattern" ]; then
regex_pattern="^\d+.\d+.?\d?$"
fi
version="$(asdf list-all "$language" | grep -E "$regex_pattern" | tail -1)"
if ! asdf list "$language" | grep -Fq "$version"; then
asdf install "$language" "$version"
asdf global "$language" "$version"
fi
}
install_asdf_ruby() {
# shellcheck disable=SC1090
. "$(brew --prefix asdf)/libexec/asdf.sh"
add_or_update_asdf_plugin "ruby" "https://github.com/asdf-vm/asdf-ruby.git"
fancy_echo "Installing latest Ruby ..."
install_asdf_language "ruby"
gem update --system
number_of_cores=$(sysctl -n hw.ncpu)
bundle config --global jobs $((number_of_cores - 1))
}
install_asdf_nodejs() {
# shellcheck disable=SC1090
. "$(brew --prefix asdf)/libexec/asdf.sh"
add_or_update_asdf_plugin "nodejs" "https://github.com/asdf-vm/asdf-nodejs.git"
fancy_echo "Installing latest Node ..."
install_asdf_language "nodejs"
}
install_asdf_erlang() {
# shellcheck disable=SC1090
. "$(brew --prefix asdf)/libexec/asdf.sh"
add_or_update_asdf_plugin "erlang" "https://github.com/asdf-vm/asdf-erlang.git"
fancy_echo "Installing latest Erlang ..."
install_asdf_language "erlang"
}
install_asdf_elixir() {
# shellcheck disable=SC1090
. "$(brew --prefix asdf)/libexec/asdf.sh"
add_or_update_asdf_plugin "elixir" "https://github.com/asdf-vm/asdf-elixir.git"
fancy_echo "Installing latest Elixir ..."
install_asdf_language "elixir" "^\d+.\d+.?\d+?-otp-\d+$"
}
install_asdf_golang() {
# shellcheck disable=SC1090
. "$(brew --prefix asdf)/libexec/asdf.sh"
add_or_update_asdf_plugin "golang" "https://github.com/asdf-community/asdf-golang.git"
fancy_echo "Installing latest Go ..."
install_asdf_language "golang" "^\d+.\d+.?\d+?-otp-\d+$"
}
append_general_dependencies() {
fancy_echo "Appending general dependencies to Brewfile"
tee "$HOME/.Brewfile" <<-EOF
# General
tap "thoughtbot/formulae"
tap "homebrew/services"
tap "universal-ctags/universal-ctags"
tap "github/gh"
# mas-cli to install macOS apps
brew "mas"
# General apps
cask "slack" unless File.directory?("/Applications/Slack.app")
cask "google-chrome" unless File.directory?("/Applications/Google Chrome.app")
cask "1password" unless File.directory?("/Applications/1Password 7.app")
cask "1password-cli"
cask "skitch" unless File.directory?("/Applications/Skitch.app")
cask "postman" unless File.directory?("/Applications/Postman.app")
cask "iterm2" unless File.directory?("/Applications/iTerm.app")
# Unix
brew "universal-ctags", args: ["HEAD"]
brew "git"
brew "openssl"
brew "gpg"
brew "zsh"
# GitHub extensions
brew "gh"
cask "github" unless File.directory?("/Applications/GitHub Desktop.app")
brew "git-lfs"
# Editor
cask "visual-studio-code" unless File.directory?("/Applications/Visual Studio Code.app")
# Programming language prerequisites and package managers
brew "libyaml" # should come after openssl
brew "coreutils"
EOF
if [ "$ARCH" != "arm64" ]; then
append_general_intel_dependencies
fi
}
append_general_intel_dependencies() {
fancy_echo "Appending web's dependencies to Brewfile"
tee -a "$HOME/.Brewfile" <<-EOF
# General apps
cask "keybase" unless File.directory?("/Applications/Keybase.app")
EOF
}
append_web_dependencies() {
fancy_echo "Appending web's dependencies to Brewfile"
tee -a "$HOME/.Brewfile" <<-EOF
# Web
tap "heroku/brew"
tap "phrase/brewed"
# Devops
cask "docker"
brew "heroku"
brew "awscli"
# Image manipulation
brew "imagemagick"
# Others
brew "yarn"
brew "phrase"
brew "libpq"
cask "jetbrains-toolbox"
EOF
append_to_zshrc 'export PATH="/opt/homebrew/opt/libpq/bin:$PATH"'
}
append_ios_dependencies() {
fancy_echo "Appending iOS's dependencies to Brewfile"
tee -a "$HOME/.Brewfile" <<-EOF
# iOS
brew "cocoapods"
cask "figma"
cask "proxyman"
cask "sourcetree"
mas "XCode", id: 497799835
EOF
}
append_android_dependencies() {
fancy_echo "Appending Android's dependencies to Brewfile"
tee -a "$HOME/.Brewfile" <<-EOF
# Android
cask "temurin"
cask "android-studio"
cask "android-sdk"
EOF
}
install_dependencies() {
fancy_echo "Updating Homebrew formulae ..."
brew update --force # https://github.com/Homebrew/brew/issues/1151
fancy_echo "Installing dependencies"
brew bundle --global --verbose --no-upgrade
fancy_echo "Installed dependencies"
}
install_laptop_local() {
if [ -f "$HOME/.laptop.local" ]; then
fancy_echo "Running your customizations from ~/.laptop.local ..."
# shellcheck disable=SC1090
. "$HOME/.laptop.local"
fi
}
install() {
read -r -p "Do you want to install Web's dependencies? [y|N] " web_dep
read -r -p "Do you want to install iOS's dependencies? [y|N] " ios_dep
read -r -p "Do you want to install Android's dependencies? [y|N] " android_dep
pre_setup
install_homebrew
append_general_dependencies
if [[ $web_dep =~ (y|yes|Y) ]];then
append_web_dependencies
fi
if [[ $ios_dep =~ (y|yes|Y) ]];then
append_ios_dependencies
fi
if [[ $android_dep =~ (y|yes|Y) ]];then
append_android_dependencies
fi
install_dependencies
if [[ $web_dep =~ (y|yes|Y) ]];then
install_asdf
install_asdf_ruby
install_asdf_nodejs
install_asdf_erlang
install_asdf_elixir
install_asdf_golang
fi
install_laptop_local
brew cleanup
}
# Run
install
# Zsh extensions
config_zsh
fancy_echo "Installation successful"