forked from pagopa/developer-laptop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmac
276 lines (227 loc) · 8.23 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
#!/bin/bash
# Welcome to the monfresh laptop script!
# Be prepared to turn your laptop (or desktop)
# into an awesome development machine.
fancy_echo() {
local fmt="$1"; shift
# shellcheck disable=SC2059
printf "\\n$fmt\\n" "$@"
}
append_to_file() {
local file="$1"
local text="$2"
if ! grep -qs "^$text$" "$file"; then
printf "\\n%s\\n" "$text" >> "$file"
fi
}
create_zshrc_and_set_it_as_shell_file() {
if [ ! -f "$HOME/.zshrc" ]; then
touch "$HOME/.zshrc"
fi
shell_file="$HOME/.zshrc"
}
create_bash_profile_and_set_it_as_shell_file() {
if [ ! -f "$HOME/.bash_profile" ]; then
touch "$HOME/.bash_profile"
fi
shell_file="$HOME/.bash_profile"
}
change_shell_to_zsh() {
fancy_echo "Please enter your password to continue."
echo "Note that there won't be visual feedback when you type your password."
echo "Type it slowly and press return, or press control-c to cancel the switch to zsh and exit the script."
create_zshrc_and_set_it_as_shell_file
chsh -s "$(command -v zsh)"
echo "Note that you can always switch back to ${bold}bash${normal} if you change your mind."
echo "The instructions for changing shells manually are available in the README."
}
# shellcheck disable=SC2154
trap 'ret=$?; test $ret -ne 0 && printf "failed\n\n" >&2; exit $ret' EXIT
set -e
if [ ! -d "$HOME/.bin/" ]; then
mkdir "$HOME/.bin"
fi
case "$SHELL" in
*/zsh) :
create_zshrc_and_set_it_as_shell_file
;;
*)
create_bash_profile_and_set_it_as_shell_file
if [ -z "$CI" ]; then
bold=$(tput bold)
normal=$(tput sgr0)
echo "Want to switch your shell from the default ${bold}bash${normal} to ${bold}zsh${normal}?"
echo "Both work fine for development, and ${bold}zsh${normal} has some extra "
echo "features for customization and tab completion."
echo "If you aren't sure or don't care, we recommend ${bold}zsh${normal}."
echo -n "Press ${bold}y${normal} to switch to zsh, ${bold}n${normal} to keep bash: "
read -r -n 1 response
if [ "$response" = "y" ]; then
fancy_echo "=== Getting ready to change your shell to zsh. ==="
if ! grep -qs "$(command -v zsh)" /etc/shells; then
echo "It looks like your version of zsh is missing from ${bold}/etc/shells${normal}."
echo "It must be added there manually before your shell can be changed."
echo "Open ${bold}/etc/shells${normal} with your favorite text editor,"
echo "then add ${bold}$(command -v zsh)${normal} in a new line and save the file."
echo -n "Once you've added it, press ${bold}y${normal} to continue, or ${bold}n${normal} to cancel: "
read -r -n 1 response
if [ "$response" = "y" ]; then
change_shell_to_zsh
else
fancy_echo "Shell will not be changed."
fi
else
change_shell_to_zsh
fi
else
fancy_echo "Shell will not be changed."
fi
else
fancy_echo "CI System detected, will not change shells"
fi
;;
esac
brew_is_installed() {
brew list -1 | grep -Fqx "$1"
}
tap_is_installed() {
brew tap | grep -Fqx "$1"
}
app_is_installed() {
local app_name
app_name=$(echo "$1" | cut -d'-' -f1)
find /Applications -iname "$app_name*" -maxdepth 1 | grep -E '.app' > /dev/null
}
# shellcheck disable=SC2016
append_to_file "$shell_file" 'export PATH="$HOME/.bin:$PATH"'
# check if dev tools are installed by checking if git is present
if ! command -v git >/dev/null; then
fancy_echo "Installing Command Line Tools ..."
fancy_echo "(check the dialog)"
xcode-select --install
fancy_echo "Command Line Tools installed."
else
fancy_echo "Command Line Tools already installed. Skipping ..."
fi
if ! command -v brew >/dev/null; then
fancy_echo "Installing Homebrew ..."
curl -fsS \
'https://raw.githubusercontent.com/Homebrew/install/master/install' | ruby
# shellcheck disable=SC2016
append_to_file "$shell_file" 'export PATH="/usr/local/bin:$PATH"'
fancy_echo "Homebrew installed."
else
fancy_echo "Homebrew already installed. Skipping ..."
fi
fancy_echo "Configuring Homebrew..."
# Remove brew-cask since it is now installed as part of brew tap caskroom/cask.
# See https://github.com/caskroom/homebrew-cask/releases/tag/v0.60.0
if brew_is_installed 'brew-cask'; then
brew uninstall --force 'brew-cask'
fi
if tap_is_installed 'caskroom/versions'; then
brew untap caskroom/versions
fi
fancy_echo "Updating Homebrew ..."
cd "$(brew --repo)" && git fetch && git reset --hard origin/master && brew update
fancy_echo "Verifying the Homebrew installation..."
if brew doctor; then
fancy_echo "Your Homebrew installation is good to go."
else
fancy_echo "Your Homebrew installation reported some errors or warnings."
echo "Review the Homebrew messages to see if any action is needed."
fi
fancy_echo "Installing formulas and casks from the Brewfile ..."
if brew bundle --file="$HOME/Brewfile"; then
fancy_echo "All formulas and casks were installed successfully."
else
fancy_echo "Some formulas or casks failed to install."
echo "This is usually due to one of the Mac apps being already installed,"
echo "in which case, you can ignore these errors."
fi
fancy_echo "Homebrew configured."
#
# VSCODE SETUP
#
fancy_echo "Configuring Visual Studio Code..."
# cli
if ! command -v code >/dev/null; then
fancy_echo "Installing Code CLI ..."
vscode_cli_url="https://raw.githubusercontent.com/microsoft/vscode/master/resources/darwin/bin/code.sh"
vscode_cli_file="/usr/local/bin/code"
curl $vscode_cli_url > $vscode_cli_file
else
fancy_echo "Code CLI already installed. Skipping ..."
fi
# plugins
code --install-extension eamodio.gitlens
code --install-extension esbenp.prettier-vscode
code --install-extension ms-python.python
code --install-extension ms-azuretools.vscode-docker
code --install-extension dbaeumer.vscode-eslint
code --install-extension vscode-icons-team.vscode-icons
code --install-extension dbaeumer.vscode-eslint
code --install-extension ms-vscode.vscode-typescript-tslint-plugin
code --install-extension VisualStudioExptTeam.vscodeintellicode
code --install-extension ms-vsliveshare.vsliveshare
code --install-extension formulahendry.terminal
code --install-extension timonwong.shellcheck
# settings
mkdir -p ~/Library/Application\ Support/Code/User/
touch ~/Library/Application\ Support/Code/User/settings.json
cat > ~/Library/Application\ Support/Code/User/settings.json <<- EOM
{
"editor.formatOnSave": true,
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"editor.fontLigatures": true,
"editor.fontFamily": "'Jetbrains Mono', Menlo, Monaco, 'Courier New', monospace",
"workbench.iconTheme": "vscode-icons",
"window.zoomLevel": 0,
"workbench.editor.enablePreview": false,
"editor.suggestSelection": "first",
"vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
"java.configuration.checkProjectSettingsExclusions": false,
"sync.gist": "7592a86456ef667729182a4ddedcde1e",
"[html]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"typescript.updateImportsOnFileMove.enabled": "always",
"editor.minimap.enabled": false
}
EOM
fancy_echo "Visual Studio Code configured."
#
# NODENV
#
# init
fancy_echo "Configuring nodenv..."
eval "nodenv init -"
# nodenv patch
fancy_echo "patching nodenv init into .zshrc file"
echo "eval \"\$(nodenv init -)\"" >> .zshrc
# nodenv yarn
fancy_echo "patching yarn with nodenv"
mkdir -p "$(nodenv root)/plugins"
git clone https://github.com/pine/nodenv-yarn-install.git "$(nodenv root)/plugins/nodenv-yarn-install"
fancy_echo "nodenv configured."
#
# SHELL
#
fancy_echo "Configuring OH-MY-ZSH..."
# oh-my-zsh
fancy_echo "Installing omyzsh..."
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
# spaceship
fancy_echo "Installing spaceship..."
git clone https://github.com/denysdovhan/spaceship-prompt.git "$ZSH_CUSTOM/themes/spaceship-prompt"
ln -s "$ZSH_CUSTOM/themes/spaceship-prompt/spaceship.zsh-theme" "$ZSH_CUSTOM/themes/spaceship.zsh-theme"
sed -i "" "/ZSH_THEME=*/ZSC_THEME=\"spaceship\"/g" .zshrc
fancy_echo "OH-MY-ZSH configured."
# save laptop.local command
if [ -f "$HOME/.laptop.local" ]; then
# shellcheck source=/dev/null
. "$HOME/.laptop.local"
fi
fancy_echo 'All done!'