-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathinstall.sh
More file actions
342 lines (287 loc) · 11.7 KB
/
install.sh
File metadata and controls
342 lines (287 loc) · 11.7 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
342
#!/usr/bin/env bash
set -e
# Colors and styling via gum
BOLD="\033[1m"
RESET="\033[0m"
# ─────────────────────────────────────────────────────────────────────────────
# Helpers
# ─────────────────────────────────────────────────────────────────────────────
ensure_homebrew() {
if ! command -v brew &>/dev/null; then
echo "Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
eval "$(/opt/homebrew/bin/brew shellenv)"
echo "Homebrew installed."
else
echo "Homebrew already installed."
fi
}
ensure_gum() {
if ! command -v gum &>/dev/null; then
echo "Installing gum..."
brew install gum
fi
}
# ─────────────────────────────────────────────────────────────────────────────
# Installation steps
# ─────────────────────────────────────────────────────────────────────────────
step_dotfiles() {
gum style --border normal --padding "0 1" --foreground 4 "Copying dotfiles to $HOME"
local files=(
".aliases"
".exports"
".gitignore"
".zshrc"
)
local dirs=(
".config/ghostty"
".config/nvim"
".config/zellij"
".config/nchat"
".gnupg"
)
for file in "${files[@]}"; do
if [[ -f "$file" ]]; then
cp "$file" "$HOME/$file"
gum style --foreground 2 " copied $file"
fi
done
for dir in "${dirs[@]}"; do
if [[ -d "$dir" ]]; then
mkdir -p "$HOME/$dir"
cp -r "$dir"/* "$HOME/$dir/" 2>/dev/null || true
gum style --foreground 2 " copied $dir/"
fi
done
}
step_git_config() {
gum style --border normal --padding "0 1" --foreground 4 "Git configuration"
# Copy .gitconfig base template if it exists
if [[ -f ".gitconfig" ]]; then
cp ".gitconfig" "$HOME/.gitconfig"
gum style --foreground 2 " copied .gitconfig"
fi
local existing_name existing_email
existing_name=$(git config --global user.name 2>/dev/null || true)
existing_email=$(git config --global user.email 2>/dev/null || true)
local git_name="$existing_name"
local git_email="$existing_email"
if [[ -n "$existing_name" && -n "$existing_email" ]]; then
gum style --foreground 3 " Current: $existing_name <$existing_email>"
if gum confirm "Change git user/email?"; then
git_name=$(gum input --placeholder "Your Git user.name" --prompt "Name: " --value "$existing_name")
git_email=$(gum input --placeholder "Your Git user.email" --prompt "Email: " --value "$existing_email")
fi
else
git_name=$(gum input --placeholder "Your Git user.name" --prompt "Name: ")
git_email=$(gum input --placeholder "Your Git user.email" --prompt "Email: ")
fi
git config --global user.name "$git_name"
git config --global user.email "$git_email"
if gum confirm "Set up GPG signing for commits?"; then
if ! command -v gpg &>/dev/null; then
gum style --foreground 3 " gpg not found. Installing via Homebrew..."
brew install gnupg
fi
local gpg_key
gpg_key=$(gpg --list-secret-keys --keyid-format=long 2>/dev/null \
| grep -E 'sec\s+rsa[0-9]+/' | sed 's|.*/||' | awk '{print $1}' | head -1 || true)
if [[ -z "$gpg_key" ]]; then
gum style --foreground 3 " No GPG key found. Generating a new one..."
local key_name key_email
key_name=$(gum input --placeholder "Full name for GPG key" --prompt "Name: " --value "$git_name")
key_email=$(gum input --placeholder "Email for GPG key" --prompt "Email: " --value "$git_email")
gpg --batch --gen-key <<GPGEOF
%no-protection
Key-Type: RSA
Key-Length: 4096
Subkey-Type: RSA
Subkey-Length: 4096
Name-Real: $key_name
Name-Email: $key_email
Expire-Date: 0
%commit
GPGEOF
gpg_key=$(gpg --list-secret-keys --keyid-format=long 2>/dev/null \
| grep -E 'sec\s+rsa4096/' | sed 's|.*/||' | awk '{print $1}' | head -1)
gum style --foreground 2 " GPG key $gpg_key generated."
# Offer to add a second email UID
if gum confirm "Add another email to this GPG key?"; then
local extra_email
extra_email=$(gum input --placeholder "Additional email" --prompt "Email: ")
local fingerprint
fingerprint=$(gpg --list-secret-keys --keyid-format=long 2>/dev/null \
| grep -A1 "^sec" | tail -1 | tr -d ' ')
gpg --quick-add-uid "$fingerprint" "$key_name <$extra_email>"
gum style --foreground 2 " Added $extra_email to GPG key."
fi
# Copy public key to clipboard for GitHub
gpg --armor --export "$gpg_key" | pbcopy
gum style --foreground 3 " Public key copied to clipboard — add it to GitHub (Settings > SSH and GPG keys)."
gum confirm "Press enter once you've added the key to GitHub" --affirmative "Done" --negative ""
else
gum style --foreground 2 " Found existing GPG key: $gpg_key"
fi
git config --global user.signingkey "$gpg_key"
git config --global commit.gpgsign true
gum style --foreground 2 " GPG signing enabled with key $gpg_key"
fi
gum style --foreground 2 " Git configured as $git_name <$git_email>"
}
step_brew_cli() {
gum style --border normal --padding "0 1" --foreground 4 "Installing CLI tools via Homebrew"
gum spin --spinner dot --title "Installing CLI tools..." -- bash brew.sh
gum style --foreground 2 " CLI tools installed."
}
step_brew_cask() {
gum style --border normal --padding "0 1" --foreground 4 "Installing GUI apps via Homebrew Cask"
gum spin --spinner dot --title "Installing GUI apps..." -- bash cask.sh
gum style --foreground 2 " GUI apps installed."
}
step_oh_my_zsh() {
gum style --border normal --padding "0 1" --foreground 4 "Installing Oh My Zsh"
if [[ -d "$HOME/.oh-my-zsh" ]]; then
gum style --foreground 3 " Oh My Zsh already installed, skipping."
else
gum spin --spinner dot --title "Installing Oh My Zsh..." -- \
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended
gum style --foreground 2 " Oh My Zsh installed."
fi
# Spaceship prompt
local spaceship_dir="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/spaceship-prompt"
if [[ -d "$spaceship_dir" ]]; then
gum style --foreground 3 " Spaceship prompt already installed, skipping."
else
gum spin --spinner dot --title "Installing Spaceship prompt..." -- \
git clone https://github.com/spaceship-prompt/spaceship-prompt.git "$spaceship_dir" --depth=1
ln -sf "$spaceship_dir/spaceship.zsh-theme" "${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/spaceship.zsh-theme"
gum style --foreground 2 " Spaceship prompt installed."
fi
}
step_languages() {
gum style --border normal --padding "0 1" --foreground 4 "Installing programming languages via asdf"
if ! command -v asdf &>/dev/null; then
gum spin --spinner dot --title "Installing asdf..." -- brew install asdf
gum style --foreground 2 " asdf installed."
fi
local languages
languages=$(gum choose --no-limit --selected "golang,nodejs,elixir,rust" \
"golang" \
"nodejs" \
"elixir" \
"rust")
while IFS= read -r lang; do
[[ -z "$lang" ]] && continue
if asdf plugin list 2>/dev/null | grep -q "^${lang}$"; then
gum style --foreground 3 " $lang plugin already added."
else
gum spin --spinner dot --title "Adding asdf plugin $lang..." -- \
asdf plugin add "$lang"
gum style --foreground 2 " $lang plugin added."
fi
gum spin --spinner dot --title "Installing latest $lang..." -- \
asdf install "$lang" latest
asdf set --home "$lang" latest
gum style --foreground 2 " $lang latest installed and set as global default."
done <<< "$languages"
}
step_claude_code() {
gum style --border normal --padding "0 1" --foreground 4 "Configuring Claude Code"
if ! command -v claude &>/dev/null; then
gum style --foreground 3 " Claude Code not found. Installing..."
gum spin --spinner dot --title "Installing Claude Code..." -- \
bash -c 'curl -fsSL https://claude.ai/install.sh | bash'
fi
mkdir -p "$HOME/.claude"
if [[ -f "$HOME/.claude/settings.json" ]]; then
# Merge hooks into existing settings using a temp file
local tmp
tmp=$(mktemp)
# Use python3 (ships with macOS) to merge hooks from dotfiles into existing settings
python3 -c "
import json, sys
with open('$HOME/.claude/settings.json') as f: existing = json.load(f)
with open('claude-code/settings.json') as f: dotfiles = json.load(f)
existing['hooks'] = dotfiles.get('hooks', {})
with open('$tmp', 'w') as f: json.dump(existing, f, indent=2, ensure_ascii=False)
print('merged')
" && mv "$tmp" "$HOME/.claude/settings.json"
gum style --foreground 2 " Merged notification hooks into existing settings."
else
cp claude-code/settings.json "$HOME/.claude/settings.json"
gum style --foreground 2 " Copied Claude Code settings."
fi
}
step_macos() {
gum style --border normal --padding "0 1" --foreground 4 "Applying macOS preferences"
if gum confirm "This will change macOS system preferences. Continue?"; then
bash osx.sh
gum style --foreground 2 " macOS preferences applied."
else
gum style --foreground 3 " Skipped macOS preferences."
fi
}
# ─────────────────────────────────────────────────────────────────────────────
# Main
# ─────────────────────────────────────────────────────────────────────────────
main() {
ensure_homebrew
ensure_gum
gum style \
--border double \
--align center \
--padding "1 3" \
--foreground 4 \
--bold \
"Dotfiles Installer" \
"github.com/vitorleal/dotfiles"
echo ""
local steps
steps=$(gum choose --no-limit --selected "Dotfiles,Git Config,CLI Tools,GUI Apps,Oh My Zsh,Languages (asdf),Claude Code,macOS Preferences" \
"Dotfiles" \
"Git Config" \
"CLI Tools" \
"GUI Apps" \
"Oh My Zsh" \
"Languages (asdf)" \
"Claude Code" \
"macOS Preferences")
echo ""
while IFS= read -r step <&3; do
case "$step" in
"Dotfiles") step_dotfiles ;;
"Git Config") step_git_config ;;
"CLI Tools") step_brew_cli ;;
"GUI Apps") step_brew_cask ;;
"Oh My Zsh") step_oh_my_zsh ;;
"Languages (asdf)") step_languages ;;
"Claude Code") step_claude_code ;;
"macOS Preferences") step_macos ;;
esac
echo ""
done 3<<< "$steps"
# Offer to re-run setup scripts
if gum confirm "Re-run any setup scripts (brew, cask, macOS)?"; then
local rerun
rerun=$(gum choose --no-limit \
"CLI Tools (brew.sh)" \
"GUI Apps (cask.sh)" \
"macOS Preferences (osx.sh)")
while IFS= read -r choice <&4; do
case "$choice" in
"CLI Tools (brew.sh)") step_brew_cli ;;
"GUI Apps (cask.sh)") step_brew_cask ;;
"macOS Preferences (osx.sh)") step_macos ;;
esac
done 4<<< "$rerun"
fi
gum style \
--border double \
--align center \
--padding "1 3" \
--foreground 2 \
--bold \
"All done!" \
"Restart your terminal to apply changes."
}
main "$@"