-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·564 lines (509 loc) · 19.1 KB
/
install.sh
File metadata and controls
executable file
·564 lines (509 loc) · 19.1 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
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
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
#!/bin/bash
# Parse arguments
DRY_RUN=false
if [[ "$1" == "--dry-run" ]] || [[ "$1" == "-n" ]]; then
DRY_RUN=true
echo "🔍 DRY RUN MODE - No files will be modified"
echo ""
fi
echo "RUNNING dotfiles repo install.sh"
# Export DOTFILES_PATH (needed by brew.sh and referenced throughout)
export DOTFILES_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
echo ""
echo "STEP: 🍺 setting up Homebrew packages"
if [[ "$OSTYPE" == "darwin"* ]]; then
if [ -f "$DOTFILES_PATH/brew/brew.sh" ]; then
if [ "$DRY_RUN" = true ]; then
echo "[DRY RUN] Would execute: brew/brew.sh"
else
bash "$DOTFILES_PATH/brew/brew.sh"
fi
else
echo "brew.sh not found in brew directory"
fi
else
echo "Skipping Homebrew setup on non-Darwin system"
fi
echo ""
echo "STEP: 💾 copying .gitignore_global"
if [ "$DRY_RUN" = true ]; then
echo "[DRY RUN] Would copy: ./git/.gitignore_global → ~/.gitignore_global"
else
cp ./git/.gitignore_global ~
echo "- copied .gitignore_global to $HOME"
fi
echo ""
echo "STEP: 💾 copying prettier formatting files"
if [ "$DRY_RUN" = true ]; then
echo "[DRY RUN] Would copy: ./prettier/.prettierrc → ~/.prettierrc"
else
cp ./prettier/.prettierrc ~
echo "- copied .prettierrc 🎨 to $HOME"
fi
echo ""
echo "STEP: 🤖 Installing Agent Definitions (AGENTS.md)"
if [ -f "./ai/AGENTS.md" ]; then
if [ "$DRY_RUN" = true ]; then
echo "[DRY RUN] Would copy: ./ai/AGENTS.md → ~/AGENTS.md"
else
# Backup existing AGENTS.md if it exists
if [ -f "$HOME/AGENTS.md" ]; then
cp "$HOME/AGENTS.md" "$HOME/AGENTS.md.backup.$(date +%Y%m%d_%H%M%S)"
echo "- backed up existing AGENTS.md"
fi
cp "./ai/AGENTS.md" "$HOME/AGENTS.md"
echo "- copied AGENTS.md to $HOME"
fi
else
echo "- AGENTS.md not found in ./ai/"
fi
echo ""
echo "STEP: 🔗 Symlinking AI configurations"
if [ "$DRY_RUN" = true ]; then
echo "[DRY RUN] Would create symlinks for AI configurations"
else
# Ensure ~/.claude directory exists
mkdir -p "$HOME/.claude"
# Remove existing CLAUDE.md if it's a file, to replace with symlink
if [ -f "$HOME/.claude/CLAUDE.md" ]; then
rm "$HOME/.claude/CLAUDE.md"
echo "- removed old ~/.claude/CLAUDE.md file"
fi
# Create symlink for CLAUDE.md
ln -sf "$HOME/AGENTS.md" "$HOME/.claude/CLAUDE.md"
echo "- symlinked ~/.claude/CLAUDE.md to ~/AGENTS.md"
# Ensure ~/.gemini directory exists
mkdir -p "$HOME/.gemini"
# Remove existing GEMINI.md if it's a file, to replace with symlink (assuming it might exist from previous manual setup)
if [ -f "$HOME/.gemini/GEMINI.md" ]; then
rm "$HOME/.gemini/GEMINI.md"
echo "- removed old ~/.gemini/GEMINI.md file"
fi
# Create symlink for GEMINI.md
ln -sf "$HOME/AGENTS.md" "$HOME/.gemini/GEMINI.md"
echo "- symlinked ~/.gemini/GEMINI.md to ~/AGENTS.md"
fi
echo ""
echo "STEP: 🤖 copying Claude Code configuration files"
# Ensure ~/.claude directory exists
mkdir -p "$HOME/.claude"
# Copy settings.json
if [ -f "./.claude/settings.json" ]; then
if [ "$DRY_RUN" = true ]; then
echo "[DRY RUN] Would copy: ./.claude/settings.json → ~/.claude/settings.json"
else
# Backup existing settings.json if it exists
if [ -f "$HOME/.claude/settings.json" ]; then
cp "$HOME/.claude/settings.json" "$HOME/.claude/settings.json.backup.$(date +%Y%m%d_%H%M%S)"
echo "- backed up existing settings.json"
fi
cp ./.claude/settings.json "$HOME/.claude/settings.json"
echo "- copied settings.json to ~/.claude/"
echo "- NOTE: You'll need to restart Claude Code for settings to take effect"
fi
else
echo "- settings.json not found in ./.claude/"
fi
echo ""
echo "STEP: 🤖 copying Gemini configuration files"
# Ensure ~/.gemini directory exists
mkdir -p "$HOME/.gemini"
# Copy settings.json
if [ -f "./ai/gemini_settings.json" ]; then
if [ "$DRY_RUN" = true ]; then
echo "[DRY RUN] Would copy: ./ai/gemini_settings.json → ~/.gemini/settings.json"
else
# Backup existing settings.json if it exists
if [ -f "$HOME/.gemini/settings.json" ]; then
cp "$HOME/.gemini/settings.json" "$HOME/.gemini/settings.json.backup.$(date +%Y%m%d_%H%M%S)"
echo "- backed up existing settings.json"
fi
cp "./ai/gemini_settings.json" "$HOME/.gemini/settings.json"
echo "- copied gemini_settings.json to ~/.gemini/"
fi
else
echo "- gemini_settings.json not found in ./ai/"
fi
echo ""
echo "STEP: 💾 copying shell configuration files e.g., bash, fish, zsh"
echo "🐚 shell is $SHELL"
# Check for bash
if [ "$SHELL" == "/bin/bash" ]; then
if [ "$DRY_RUN" = true ]; then
echo "[DRY RUN] Would copy: ./shell/bash/.bashrc → ~/.bashrc"
echo "[DRY RUN] Would copy: ./shell/bash/.bash_profile → ~/.bash_profile"
else
if [ -f "$HOME/.bashrc" ]; then
cp "$HOME/.bashrc" "$HOME/.bashrc.backup.$(date +%Y%m%d_%H%M%S)"
echo "- backed up existing .bashrc"
fi
if [ -f "$HOME/.bash_profile" ]; then
cp "$HOME/.bash_profile" "$HOME/.bash_profile.backup.$(date +%Y%m%d_%H%M%S)"
echo "- backed up existing .bash_profile"
fi
cp ./shell/bash/.bashrc $HOME/.bashrc
cp ./shell/bash/.bash_profile $HOME/.bash_profile
echo "- copied bash 👾 configuration files to $HOME"
fi
fi
# Check for zsh
if [ "$SHELL" == "/bin/zsh" ]; then
if [ "$DRY_RUN" = true ]; then
echo "[DRY RUN] Would copy: ./shell/zsh/.zshrc → ~/.zshrc"
else
if [ -f "$HOME/.zshrc" ]; then
cp "$HOME/.zshrc" "$HOME/.zshrc.backup.$(date +%Y%m%d_%H%M%S)"
echo "- backed up existing .zshrc"
fi
cp ./shell/zsh/.zshrc $HOME/.zshrc
echo "- copied zsh 🍎 configuration files to $HOME"
fi
fi
# Check for fish (regardless of current shell)
if command -v fish &> /dev/null; then
if [ "$DRY_RUN" = true ]; then
echo "[DRY RUN] Would copy: ./shell/fish/config.fish → ~/.config/fish/config.fish"
else
if [ -f "$HOME/.config/fish/config.fish" ]; then
cp "$HOME/.config/fish/config.fish" "$HOME/.config/fish/config.fish.backup.$(date +%Y%m%d_%H%M%S)"
echo "- backed up existing config.fish"
fi
cp ./shell/fish/config.fish $HOME/.config/fish/config.fish
echo "- copied fish 🐟 configuration files to $HOME/.config/fish"
fi
fi
# If none of the above conditions are met, print a message
if [ "$SHELL" != "/bin/bash" ] && [ "$SHELL" != "/bin/zsh" ] && ! command -v fish &> /dev/null; then
echo "- no unix shell dotfiles copied. Please ensure you have bash, zsh, or fish installed."
fi
# Function to check if VS Code is installed
check_vscode_installed() {
if command -v code &> /dev/null; then
return 0
else
echo "Visual Studio Code is not installed."
return 1
fi
}
copy_vscode_settings() {
local dotfiles_dir="$(cd $(dirname "${BASH_SOURCE[0]}") && pwd)"
local settings_source="$dotfiles_dir/code/settings.json"
local extensions_source="$dotfiles_dir/code/extensions.json"
local vscode_dir="$HOME/.vscode"
local settings_target="$HOME/Library/Application Support/Code/User/settings.json"
# Check if VS Code settings directory exists (handle spaces in path)
if [ ! -d "$HOME/Library/Application Support/Code/User" ]; then
echo "- VS Code settings directory not found. Please ensure Visual Studio Code is installed."
return 1
fi
# Copy the settings.json file
if [ -f "$settings_source" ]; then
if [ "$DRY_RUN" = true ]; then
echo "[DRY RUN] Would copy: $settings_source → $settings_target"
else
if cp "$settings_source" "$settings_target"; then
echo "- copied VS Code settings.json to $settings_target"
else
echo "- failed to copy VS Code settings.json to $settings_target"
return 1
fi
fi
else
echo "VS Code settings.json not found in $dotfiles_dir/code"
fi
# Check if VS Code extensions directory exists
if [ ! -d "$vscode_dir" ]; then
echo "- $vscode_dir not found. Please ensure Visual Studio Code is installed."
return 1
fi
# Copy the extensions.json file
if [ -f "$extensions_source" ]; then
if [ "$DRY_RUN" = true ]; then
echo "[DRY RUN] Would copy: $extensions_source → $vscode_dir/extensions.json"
else
if cp "$extensions_source" "$vscode_dir/extensions.json"; then
echo "- copied VS Code extensions.json to $vscode_dir/extensions.json"
else
echo "- failed to copy VS Code extensions.json to $vscode_dir/extensions.json"
return 1
fi
fi
else
echo "- VS Code extensions.json not found in $dotfiles_dir/code"
fi
}
copy_zed_settings() {
local dotfiles_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
local settings_source="$dotfiles_dir/zed/settings.json"
local keymap_source="$dotfiles_dir/zed/keymap.json"
local zed_config_dir="$HOME/.config/zed"
# Ensure the target directory exists
mkdir -p "$zed_config_dir"
# Copy settings.json
if [ -f "$settings_source" ]; then
if [ "$DRY_RUN" = true ]; then
echo "[DRY RUN] Would copy: $settings_source → $zed_config_dir/settings.json"
else
if cp "$settings_source" "$zed_config_dir/settings.json"; then
echo "- copied Zed settings.json to $zed_config_dir/settings.json"
else
echo "- failed to copy Zed settings.json to $zed_config_dir/settings.json"
fi
fi
else
echo "- Zed settings.json not found in $dotfiles_dir/zed"
fi
# Copy keymap.json
if [ -f "$keymap_source" ]; then
if [ "$DRY_RUN" = true ]; then
echo "[DRY RUN] Would copy: $keymap_source → $zed_config_dir/keymap.json"
else
if cp "$keymap_source" "$zed_config_dir/keymap.json"; then
echo "- copied Zed keymap.json to $zed_config_dir/keymap.json"
else
echo "- failed to copy Zed keymap.json to $zed_config_dir/keymap.json"
fi
fi
else
echo "- Zed keymap.json not found in $dotfiles_dir/zed"
fi
}
copy_ghostty_settings() {
local dotfiles_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
local config_source="$dotfiles_dir/ghostty/config"
local ghostty_config_dir="$HOME/.config/ghostty"
local config_target="$ghostty_config_dir/config"
mkdir -p "$ghostty_config_dir"
if [ -f "$config_source" ]; then
if [ "$DRY_RUN" = true ]; then
echo "[DRY RUN] Would copy: $config_source → $config_target"
else
if [ -f "$config_target" ]; then
cp "$config_target" "$config_target.backup.$(date +%Y%m%d_%H%M%S)"
echo "- backed up existing ghostty config"
fi
if cp "$config_source" "$config_target"; then
echo "- copied Ghostty config to $config_target"
else
echo "- failed to copy Ghostty config to $config_target"
fi
fi
else
echo "- ghostty/config not found in $dotfiles_dir/ghostty"
fi
}
copy_starship_settings() {
local dotfiles_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
local config_source="$dotfiles_dir/starship/starship.toml"
local config_target="$HOME/.config/starship.toml"
mkdir -p "$HOME/.config"
if [ -f "$config_source" ]; then
if [ "$DRY_RUN" = true ]; then
echo "[DRY RUN] Would copy: $config_source → $config_target"
else
if [ -f "$config_target" ]; then
cp "$config_target" "$config_target.backup.$(date +%Y%m%d_%H%M%S)"
echo "- backed up existing starship config"
fi
if cp "$config_source" "$config_target"; then
echo "- copied Starship config to $config_target"
else
echo "- failed to copy Starship config to $config_target"
fi
fi
else
echo "- starship/starship.toml not found in $dotfiles_dir/starship"
fi
}
copy_atuin_settings() {
local dotfiles_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
local config_source="$dotfiles_dir/atuin/config.toml"
local atuin_config_dir="$HOME/.config/atuin"
local config_target="$atuin_config_dir/config.toml"
mkdir -p "$atuin_config_dir"
if [ -f "$config_source" ]; then
if [ "$DRY_RUN" = true ]; then
echo "[DRY RUN] Would copy: $config_source → $config_target"
else
if [ -f "$config_target" ]; then
cp "$config_target" "$config_target.backup.$(date +%Y%m%d_%H%M%S)"
echo "- backed up existing atuin config"
fi
if cp "$config_source" "$config_target"; then
echo "- copied Atuin config to $config_target"
else
echo "- failed to copy Atuin config to $config_target"
fi
fi
else
echo "- atuin/config.toml not found in $dotfiles_dir/atuin"
fi
}
copy_nvim_settings() {
local dotfiles_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
local nvim_config_dir="$HOME/.config/nvim"
local nvim_files=("init.lua" "lazy-lock.json" ".avante_pref")
mkdir -p "$nvim_config_dir"
for file in "${nvim_files[@]}"; do
local source="$dotfiles_dir/nvim/$file"
local target="$nvim_config_dir/$file"
if [ -f "$source" ]; then
if [ "$DRY_RUN" = true ]; then
echo "[DRY RUN] Would copy: $source → $target"
else
if [ -f "$target" ]; then
cp "$target" "$target.backup.$(date +%Y%m%d_%H%M%S)"
echo "- backed up existing $file"
fi
if cp "$source" "$target"; then
echo "- copied $file to $nvim_config_dir/"
else
echo "- failed to copy $file to $nvim_config_dir/"
fi
fi
else
echo "- nvim/$file not found in $dotfiles_dir/nvim"
fi
done
}
# Function to clean up old backups, keeping only the two most recent
cleanup_backups() {
local target_dir="$1"
local base_filename="$2"
local backup_files=()
# Find all backup files for the given base_filename, sorted by name (chronological)
while IFS= read -r -d $'\0' file; do
backup_files+=("$file")
done < <(find "$target_dir" -maxdepth 1 -type f -name "${base_filename}.backup.*" -print0 | sort -z)
local num_backups=${#backup_files[@]}
if (( num_backups > 2 )); then
echo "- Found $num_backups backups for $base_filename in "$target_dir". Keeping the 2 newest."
# Delete backups from the 3rd oldest onwards
for (( i=0; i < num_backups - 2; i++ )); do
if [ "$DRY_RUN" = true ]; then
echo "[DRY RUN] Would delete old backup: ${backup_files[i]}"
else
rm "${backup_files[i]}"
echo " Deleted: ${backup_files[i]}"
fi
done
fi
}
echo ""
echo "STEP: 💾 copying VS Code IDE configs"
if check_vscode_installed; then
copy_vscode_settings
else
echo "Installation of VS Code settings.json skipped due to VS Code not being installed."
fi
echo ""
echo "STEP: 💾 copying Zed IDE configs"
if command -v zed &> /dev/null; then
copy_zed_settings
else
echo "Zed is not installed. Installation of Zed settings.json skipped."
fi
echo ""
echo "STEP: 👻 copying Ghostty terminal config"
if brew list --cask ghostty &> /dev/null 2>&1; then
copy_ghostty_settings
else
echo "Ghostty is not installed. Skipping ghostty config."
fi
echo ""
echo "STEP: 🚀 copying Starship prompt config"
if command -v starship &> /dev/null; then
copy_starship_settings
else
echo "Starship is not installed. Skipping starship config."
fi
echo ""
echo "STEP: copying Atuin config"
if command -v atuin &> /dev/null; then
copy_atuin_settings
else
echo "Atuin is not installed. Skipping atuin config."
fi
echo ""
echo "STEP: 💾 copying Neovim config"
if command -v nvim &> /dev/null; then
copy_nvim_settings
else
echo "Neovim is not installed. Skipping Neovim configuration."
fi
echo ""
echo "STEP: 🍎 configuring macOS defaults"
if [[ "$OSTYPE" == "darwin"* ]]; then
if [ -f "$DOTFILES_PATH/mac/macos.sh" ]; then
if [ "$DRY_RUN" = true ]; then
echo "[DRY RUN] Would execute: mac/macos.sh"
else
bash "$DOTFILES_PATH/mac/macos.sh"
fi
else
echo "macos.sh not found in mac directory"
fi
else
echo "Skipping macOS defaults on non-Darwin system"
fi
echo ""
echo "STEP: 🧹 Cleaning up old backups"
if [ "$DRY_RUN" = true ]; then
echo "[DRY RUN] Would clean up old backup files, keeping only the 2 most recent."
else
# Clean up AGENTS.md backups
cleanup_backups "$HOME" "AGENTS.md"
# Clean up Claude settings.json backups
cleanup_backups "$HOME/.claude" "settings.json"
# Clean up old CLAUDE.md files (that were backed up before it became a symlink)
cleanup_backups "$HOME/.claude" "CLAUDE.md"
# Clean up Gemini settings.json backups
cleanup_backups "$HOME/.gemini" "settings.json"
# Clean up shell backups
cleanup_backups "$HOME" ".bashrc"
cleanup_backups "$HOME" ".bash_profile"
cleanup_backups "$HOME" ".zshrc"
cleanup_backups "$HOME/.config/fish" "config.fish"
# Clean up Atuin config backups
cleanup_backups "$HOME/.config/atuin" "config.toml"
# Clean up Ghostty config backups
cleanup_backups "$HOME/.config/ghostty" "config"
# Clean up Starship config backups
cleanup_backups "$HOME/.config" "starship.toml"
# Clean up Neovim config backups
cleanup_backups "$HOME/.config/nvim" "init.lua"
cleanup_backups "$HOME/.config/nvim" "lazy-lock.json"
cleanup_backups "$HOME/.config/nvim" ".avante_pref"
fi
echo ""
echo "STEP: 🎭 Installing Playwright browser binaries"
if command -v uv &>/dev/null; then
if [ "$DRY_RUN" = true ]; then
echo "[DRY RUN] Would run: uv run --with playwright python3 -m playwright install chromium"
else
uv run --with playwright python3 -m playwright install chromium
echo "- Playwright chromium binary installed"
fi
else
echo "- uv not found, skipping Playwright install (run 'brew bundle' first)"
fi
echo ""
echo "======================================"
echo "📝 Git User Configuration"
echo "======================================"
echo ""
echo "Your current git user settings:"
echo " Name: $(git config --global user.name 2>/dev/null || echo '(not set)')"
echo " Email: $(git config --global user.email 2>/dev/null || echo '(not set)')"
echo " GPG Key: $(git config --global user.signingkey 2>/dev/null || echo '(not set)')"
echo " GPG Sign: $(git config --global commit.gpgsign 2>/dev/null || echo '(not set)')"
echo ""
echo "To configure your git identity (required for commits):"
echo " git config --global user.name \"Your Name\""
echo " git config --global user.email \"your@email.com\""
echo ""
echo "Optional - To enable GPG commit signing:"
echo " 1. List your GPG keys: gpg --list-secret-keys --keyid-format=long"
echo " 2. Set signing key: git config --global user.signingkey YOUR_KEY_ID"
echo " 3. Enable auto-signing: git config --global commit.gpgsign true"
echo ""