-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·285 lines (255 loc) · 8.88 KB
/
setup.sh
File metadata and controls
executable file
·285 lines (255 loc) · 8.88 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
#!/bin/bash
brewCasks="1password iterm2 slack brave-browser
visual-studio-code steam vlc zoom
docker docker-desktop dbeaver-community claude
nikitabobko/tap/aerospace ngrok google-chrome whatsapp
plex-media-server pop"
brews="go git gh bat zsh z vim wget curl htop pipenv gcc tree
jq coreutils rsync tmux watch ffmpeg
gdrive goreleaser rename sqlite
fswatch oven-sh/bun/bun uv"
npmGlobals="vercel http-server npm-check-updates pnpm @anthropic-ai/claude-code"
# don't check home brew for updates
export HOMEBREW_NO_AUTO_UPDATE=1
# --- colors and formatting ---
bold='\033[1m'
dim='\033[2m'
red='\033[31m'
green='\033[32m'
yellow='\033[33m'
blue='\033[34m'
reset='\033[0m'
spinner_pid=""
spinner_frames=('⠋' '⠙' '⠹' '⠸' '⠼' '⠴' '⠦' '⠧' '⠇' '⠏')
start_spinner() {
local msg="$1"
tput civis # hide cursor
(
i=0
while true; do
printf "\r ${blue}%s${reset} %s" "${spinner_frames[$((i % ${#spinner_frames[@]}))]}" "$msg"
i=$((i + 1))
sleep 0.08
done
) &
spinner_pid=$!
}
stop_spinner() {
if [ -n "$spinner_pid" ]; then
kill "$spinner_pid" 2>/dev/null
wait "$spinner_pid" 2>/dev/null
spinner_pid=""
fi
printf "\r\033[2K" # clear the line
tput cnorm # show cursor
}
print_success() {
printf " ${green}✓${reset} %s\n" "$1"
}
print_skip() {
printf " ${dim}✓ %s (already installed)${reset}\n" "$1"
}
print_fail() {
printf " ${red}✗${reset} %s ${red}(failed)${reset}\n" "$1"
}
print_header() {
echo ""
printf "${bold}━━━ %s ━━━${reset}\n" "$1"
}
# run a command with spinner, redirect output to logfile
# on failure, print the log. on success, stay clean.
run_install() {
local name="$1"
local logfile
logfile=$(mktemp)
shift
start_spinner "installing $name..."
if "$@" > "$logfile" 2>&1; then
stop_spinner
print_success "$name"
else
stop_spinner
print_fail "$name"
printf " ${dim}log: %s${reset}\n" "$logfile"
sed 's/^/ /' "$logfile"
return 1
fi
rm -f "$logfile"
}
# ask for sudo up front so we don't need to ask for passwords later
sudo -v
# keep sudo alive in the background
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &
main() {
promptGitInfo
setupMacosDefaults
setupBrew
setupBrewCasks $brewCasks
setupBrews $brews
setupGit
setupNvm
setupNpmGlobals $npmGlobals
setupGo
setupOhMyZsh
echo ""
printf " ${green}${bold}✔ Setup complete — logging out to apply settings${reset}\n"
echo ""
sleep 3
launchctl bootout user/$(id -u)
}
# ----------- functions -------------
containsElement() {
local e match="$1"
shift
for e; do [[ "$e" == "$match" ]] && return 0; done
return 1
}
setupOhMyZsh() {
print_header "Oh My Zsh"
if [ -d "$HOME/.oh-my-zsh" ]; then
print_skip "oh-my-zsh"
return
fi
run_install "oh-my-zsh" sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended
echo "source ~/.zshrc-ext" >>~/.zshrc
chsh -s "$(which zsh)"
echo "plugins=(git colored-man colorize pip python brew macos zsh-syntax-highlighting)" >~/.zshrc-ext
echo ". $(brew --prefix)/etc/profile.d/z.sh" >>~/.zshrc-ext
echo "disable r functions" >>~/.zshrc-ext
}
setupNvm() {
print_header "NVM & Node"
if [ ! -d "$HOME/.nvm" ]; then
NVM_DIR=""
nvmLatest=$(curl -sL https://github.com/nvm-sh/nvm/releases/latest | egrep -so "[0-9]*\.[0-9]*\.[0-9]*" | head -n 1 | tr -s " ")
run_install "nvm v$nvmLatest" bash -c "curl -s -o- 'https://raw.githubusercontent.com/nvm-sh/nvm/v${nvmLatest}/install.sh' | bash"
else
print_skip "nvm"
fi
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
if ! grep -q 'NVM_DIR' ~/.zshrc-ext 2>/dev/null; then
echo 'export NVM_DIR="$HOME/.nvm"' >> ~/.zshrc-ext
echo '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"' >> ~/.zshrc-ext
fi
if ! command -v node >/dev/null 2>&1; then
nodeLatest=$(curl -sL https://github.com/nodejs/node/releases/latest | egrep -so "[0-9]*\.[0-9]*\.[0-9]*" | head -n 1 | tr -s " ")
run_install "node v$nodeLatest" nvm install --no-progress $nodeLatest
else
print_skip "node $(node -v)"
fi
}
setupNpmGlobals() {
npmGlobals=("$@")
print_header "NPM Globals"
for i in "${npmGlobals[@]}"; do
if npm list -g "$i" >/dev/null 2>&1; then
print_skip "$i"
else
run_install "$i" npm install -g "$i"
fi
done
}
setupGo() {
print_header "Go"
if grep -q 'GOPATH' ~/.zshrc-ext 2>/dev/null; then
print_skip "go paths"
return
fi
echo 'export GOPATH="${HOME}/.go"' >>~/.zshrc-ext
echo 'export GOROOT="$(brew --prefix golang)/libexec"' >>~/.zshrc-ext
echo 'export PATH="$PATH:${GOPATH}/bin:${GOROOT}/bin"' >>~/.zshrc-ext
print_success "go paths"
}
promptGitInfo() {
gitEmail=$(git config --global user.email)
gitUsername=$(git config --global user.name)
if [ "$gitUsername" == "" ]; then
printf " ${yellow}?${reset} Enter git username: "
read gitUsername
fi
if [ "$gitEmail" == "" ]; then
printf " ${yellow}?${reset} Enter git email: "
read gitEmail
fi
if ! gh auth status >/dev/null 2>&1; then
gh auth login --git-protocol ssh --web --hostname github.com
fi
}
setupGit() {
print_header "Git"
git config --global user.name "$gitUsername"
git config --global user.email "$gitEmail"
git config --global pager.branch false
print_success "git config"
if [ -f ~/.ssh/id_ed25519 ]; then
print_skip "ssh key"
else
ssh-keygen -t ed25519 -C "$gitEmail" -q -N "" -f ~/.ssh/id_ed25519
print_success "ssh key"
fi
local keyTitle
keyTitle="$(scutil --get ComputerName)"
if gh ssh-key list | grep -q "$keyTitle"; then
print_skip "ssh key on github"
else
gh ssh-key add ~/.ssh/id_ed25519.pub --title "$keyTitle"
print_success "ssh key added to github"
fi
}
setupBrews() {
brews=("$@")
print_header "Brew Formulae"
installedBrews=$(brew list)
for i in "${brews[@]}"; do
local short="${i##*/}"
if containsElement "$short" ${installedBrews[@]}; then
print_skip "$short"
else
run_install "$short" brew install "$i"
fi
done
}
setupBrew() {
print_header "Homebrew"
if command -v brew >/dev/null 2>&1; then
print_skip "homebrew"
else
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
# ensure brew is in PATH (needed on Apple Silicon where brew is at /opt/homebrew)
if [ -x /opt/homebrew/bin/brew ]; then
eval "$(/opt/homebrew/bin/brew shellenv)"
elif [ -x /usr/local/bin/brew ]; then
eval "$(/usr/local/bin/brew shellenv)"
fi
}
setupMacosDefaults() {
print_header "macOS Defaults"
defaults write -g InitialKeyRepeat -int 13 # normal minimum is 15 (225 ms)
defaults write -g KeyRepeat -int 2 # normal minimum is 2 (30 ms)
print_success "key repeat"
defaults write com.apple.dock persistent-apps -array
killall Dock
print_success "clean dock"
if osascript -e 'tell application "System Events" to get the name of every login item' | grep -q AeroSpace; then
print_skip "aerospace login item"
else
osascript -e 'tell application "System Events" to make login item at end with properties {name: "AeroSpace", path: "/Applications/AeroSpace.app", hidden: false}'
print_success "aerospace login item"
fi
}
setupBrewCasks() {
brewCasks=("$@")
print_header "Brew Casks"
installedBrews=$(brew list)
for i in "${brewCasks[@]}"; do
local short="${i##*/}"
if containsElement "$short" ${installedBrews[@]}; then
print_skip "$short"
else
run_install "$short" brew install --cask "$i"
fi
done
}
main