-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall
More file actions
executable file
·341 lines (281 loc) · 8.92 KB
/
Copy pathinstall
File metadata and controls
executable file
·341 lines (281 loc) · 8.92 KB
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
#!/usr/bin/env bash
# Mac-Setup CLI
#
# Copyright (c) 2025 Marcos Borges
# https://marcosborges.phd
#
readonly MAC_SETUP_DOC="https://marcosborgesphd.github.io/mac-setup"
readonly VERSION="0.0.3"
readonly PREFIX="${HOME}"
readonly CR='\033[91m'
readonly CG='\033[92m'
readonly CM='\033[95m'
readonly NC='\033[0m'
set -euo pipefail
usage() {
cat <<'EOF'
Usage: install [options]
Mac Development Setup CLI tool.
Options
-h, --help Display this help message
-v, --version Show version details
git Install and set up Git
gitconfig Set up Git
terminal Install and set up Starship and Zsh
zsh Set up Zsh
vscode Install and set up VS Code and its extensions
vscode_config Set up VS Code
EOF
}
error() {
usage
printf "${CR}\nError:${NC} Illegal option!\n"
}
abort() {
printf "\n${CR}Aborted by user.${NC}\n"
exit 1
}
trap abort SIGINT # Ctrl-C
version() {
printf "Mac-Setup ${VERSION}\n"
}
wait_for_user() {
printf "\nPress ${CG}[ENTER]${NC} to continue, "
printf "or ${CR}[any other key]${NC} to abort.\n"
read -rsn 1 key
if [[ ${key} != "" ]]; then
abort
fi
}
wait_for_sudo() {
# Request sudo password
if ! sudo -vn 2>/dev/null; then
printf "\n${CM}Requesting sudo privileges for ${USER}...${NC}\n"
sudo -v
fi
# Abort if no sudo privileges
if ! sudo -vn 2>/dev/null; then
printf "Sudo privileges are required to run this script. "
printf "${CR}Aborting.${NC}\n"
exit 1
fi
printf "\n${CG}Sudo privileges are active for this script.${NC}\n\n"
}
brew_init() {
if [[ "$(/usr/bin/uname -m)" == "arm64" ]]; then
HOMEBREW='/opt/homebrew' # ARM
else
HOMEBREW='/usr/local' # Intel
fi
if [[ -x "${HOMEBREW}/bin/brew" ]]; then
eval "$(${HOMEBREW}/bin/brew shellenv)"
else
printf "\nInstall Homebrew and then re-run this script.\n"
printf "${CM}Learn more:${NC} ${MAC_SETUP_DOC}\n\n"
printf "${CR}Homebrew is required to continue.${NC}\n"
exit 1
fi
}
brew_update() {
printf "${CM}Updating Homebrew...${NC}\n"
brew_init
brew update
}
git_install() {
printf "${CM}Installing Git...${NC}\n"
brew install git || true
printf "\n${CG}Git installation completed successfully.${NC}\n\n"
}
git_config() {
printf "${CM}Configuring Git...${NC}\n"
printf "Enter your Git username: "
read -r GIT_USER_NAME
printf "Enter your Git email: "
read -r GIT_USER_EMAIL
printf "\n${CM}Confirming your Git configuration:${NC}\n"
printf " Username: ${GIT_USER_NAME}\n"
printf " Email: ${GIT_USER_EMAIL}\n"
wait_for_user
git config --global user.name "${GIT_USER_NAME}"
git config --global user.email "${GIT_USER_EMAIL}"
git config --global color.ui true
git config --global color.status.changed "yellow bold"
git config --global color.status.untracked "red bold"
git config --global color.status.added "green bold"
git config --global color.status.updated "cyan bold"
git config --global color.status.branch "magenta bold"
git config --global color.status.header "cyan bold"
printf "\n${CG}Git configuration completed.${NC}\n\n"
}
terminal_install() {
printf "${CM}Installing Starship shell prompt...${NC}\n"
brew install starship
printf "${CM}Installing Zsh plugins...${NC}\n"
brew install zsh-autosuggestions zsh-syntax-highlighting
printf "${CM}Installing GNU Coreutils and Bat...${NC}\n"
brew install coreutils bat
printf "${CM}Installing JetBrains Mono Nerd Font...${NC}\n"
brew install font-jetbrains-mono-nerd-font
printf "\n${CG}Terminal installation completed successfully.${NC}\n\n"
}
terminal_config() {
printf "${CM}Configuring Zsh...${NC}\n"
printf "Backing up the .zshrc file...\n"
if [[ -f "${HOME}/.zshrc" ]]; then
cp "${HOME}/.zshrc" "${HOME}/.zshrc.bkp"
fi
printf "Updating the .zshrc file...\n"
echo "$(terminal_zshrc)" > "${HOME}/.zshrc"
printf "\n${CG}Terminal configuration completed successfully.${NC}\n"
printf "Restart your terminal.\n\n"
}
terminal_zshrc() {
cat <<'EOF'
# Homebrew environment
if [[ "$(/usr/bin/uname -m)" == "arm64" ]]; then
HOMEBREW='/opt/homebrew' # ARM
else
HOMEBREW='/usr/local' # Intel
fi
eval "$(${HOMEBREW}/bin/brew shellenv)"
# Zsh completion
autoload -Uz compinit && compinit
zstyle ':completion:*' menu select
# Zsh plugins
source "${HOMEBREW}/share/zsh-autosuggestions/zsh-autosuggestions.zsh"
source "${HOMEBREW}/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh"
# Starship prompt
eval "$(starship init zsh)"
# Keybindings for history search
bindkey '^P' history-beginning-search-backward # Ctrl-P
bindkey '^N' history-beginning-search-forward # Ctrl-N
bindkey '^[[A' history-beginning-search-backward # Up arrow
bindkey '^[[B' history-beginning-search-forward # Down arrow
# Aliases for better defaults
alias cat="bat"
alias grep="grep --color=auto"
alias ls="gls --color --group-directories-first"
# VIM environment
export VIMINIT='syntax on | set number'
# History
setopt INC_APPEND_HISTORY # Write history as commands are entered
setopt HIST_IGNORE_ALL_DUPS # Remove older duplicate entries
setopt HIST_REDUCE_BLANKS # Remove extra spaces
setopt HIST_IGNORE_SPACE # Commands starting with space not saved
EOF
}
vscode_install() {
printf "${CM}Installing VS Code...${NC}\n"
brew install visual-studio-code
wait_for_sudo
printf "${CM}Installing 'code' command in PATH...${NC}\n"
local SOURCE='/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code'
local TARGET='/usr/local/bin/code'
sudo ln -snf "${SOURCE}" "${TARGET}"
printf "${CM}Installing VS Code plugins...${NC}\n"
code --install-extension ms-vscode.live-server
code --install-extension ms-python.python
code --install-extension ms-vscode.cpptools
code --install-extension rust-lang.rust-analyzer
code --install-extension James-Yu.latex-workshop
printf "\n${CG}VS Code installation completed successfully.${NC}\n\n"
}
vscode_config() {
printf "${CM}Configuring VS Code...${NC}\n"
printf "Setting VS Code as the default Git editor, diff, and merge tool...\n"
git config --global core.editor 'code --wait'
git config --global diff.tool vscode
git config --global difftool.vscode.cmd 'code --wait --diff $LOCAL $REMOTE'
git config --global merge.tool vscode
git config --global mergetool.vscode.cmd 'code --wait $MERGED'
printf "Backing up VS Code settings to '~/Downloads'...\n"
cp "${HOME}/Library/Application Support/Code/User/settings.json" "${HOME}/Downloads"
printf "Updating VS Code settings...\n"
echo "$(vscode_settings)" > "${HOME}/Library/Application Support/Code/User/settings.json"
printf "\n${CG}VS Code configuration completed successfully.${NC}\n"
}
vscode_settings() {
cat <<'EOF'
{
"window.newWindowDimensions": "maximized",
"window.title": "${folderPath}",
"workbench.activityBar.location":"bottom",
"workbench.startupEditor": "newUntitledFile",
"extensions.ignoreRecommendations": true,
"telemetry.telemetryLevel": "off",
"editor.fontFamily": "JetBrainsMono Nerd Font",
"editor.fontSize": 14,
"editor.rulers": [80, 120],
"editor.minimap.enabled": false,
"terminal.integrated.fontFamily": "JetBrainsMono Nerd Font",
"terminal.integrated.fontSize": 14,
"files.trimTrailingWhitespace": true,
"files.associations": { "*.mdx": "markdown" },
"latex-workshop.latex.recipe.default": "Latexmk (LuaLaTex)",
"latex-workshop.latex.outDir": "./build",
"latex-workshop.latex.recipes": [
{ "name": "Latexmk (LuaLaTex)", "tools": ["latexmk (lualatex)"] }
],
"latex-workshop.latex.tools": [
{
"name": "latexmk (lualatex)",
"command": "latexmk",
"args": [
"-lualatex",
"-shell-escape",
"-synctex=1",
"-interaction=nonstopmode",
"-output-directory=./build",
"%DOC%"
]
}
]
}
EOF
}
# --- Check for no arguments ---
if [[ $# -eq 0 ]]; then
usage
exit 1
fi
# --- Parse arguments ---
for arg in "$@"; do
case "${arg}" in
-v|--version)
version;
exit 0
;;
-h|--help)
usage
exit 0
;;
git)
brew_update
git_install
git_config
;;
gitconfig)
git_config
;;
terminal)
brew_update
terminal_install
terminal_config
;;
zsh)
terminal_config
;;
vscode)
brew_update
vscode_install
vscode_config
;;
vscode_config)
vscode_config
;;
--|-*|*)
error
exit 1
;;
esac
done