-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·356 lines (293 loc) · 12.8 KB
/
install.sh
File metadata and controls
executable file
·356 lines (293 loc) · 12.8 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
#!/bin/bash
# Dotfiles installation script
# Creates symlinks from dotfiles repo to home directory
set -e
DOTFILES_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# ─────────────────────────────────────────────────────────────
# Output helpers
# ─────────────────────────────────────────────────────────────
# Colors (auto-disable if not a terminal)
if [[ -t 1 ]]; then
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[0;33m'
CYAN='\033[0;36m'
BOLD='\033[1m'
DIM='\033[2m'
RESET='\033[0m'
else
GREEN='' RED='' YELLOW='' CYAN='' BOLD='' DIM='' RESET=''
fi
section() {
printf "\n${BOLD}%s${RESET}\n" "$1"
}
success() {
printf " ${GREEN}✓${RESET} %s\n" "$1"
}
success_dim() {
# For "exists" or "no change" cases - dimmed annotation
printf " ${GREEN}✓${RESET} %s ${DIM}%s${RESET}\n" "$1" "$2"
}
info() {
printf " ${CYAN}→${RESET} %s\n" "$1"
}
warn() {
printf " ${YELLOW}!${RESET} %s\n" "$1"
}
error() {
printf " ${RED}✗${RESET} %s\n" "$1"
}
# ─────────────────────────────────────────────────────────────
# Ensure required tools are installed (system-wide)
# ─────────────────────────────────────────────────────────────
ensure_homebrew() {
if ! command -v brew >/dev/null 2>&1; then
echo "Homebrew is required to install dependencies. Install from https://brew.sh and rerun."
exit 1
fi
}
install_bun() {
if ! command -v bun >/dev/null 2>&1; then
info "Installing bun..."
curl -fsSL https://bun.sh/install | bash
fi
}
install_cursor() {
# cursor.com/install sets up both the `cursor` shim and `agent` binary
# in ~/.local/bin, with versioned agent bundles in ~/.local/share/cursor-agent/
if [[ ! -x "$HOME/.local/bin/agent" ]]; then
info "Installing Cursor CLI + agent..."
curl -fsSL https://cursor.com/install | bash
fi
}
install_dependencies() {
section "Dependencies"
ensure_homebrew
brew bundle install --file="$DOTFILES_DIR/Brewfile" 2>&1 | grep -E "^(Using|Installing|Upgrading)" | sed 's/^/ /'
install_bun
install_cursor
success "Dependencies installed"
}
if [[ "${SKIP_DEPENDENCY_INSTALL:-0}" != "1" ]]; then
install_dependencies
fi
# Create backup directory
BACKUP_DIR="$HOME/.dotfiles-backup/$(date +%Y%m%d-%H%M%S)"
BACKUP_CREATED=false
backup_and_link() {
local source="$1"
local target="$2"
local label="$3"
if [[ -e "$target" && ! -L "$target" ]]; then
if [[ "$BACKUP_CREATED" == "false" ]]; then
mkdir -p "$BACKUP_DIR"
BACKUP_CREATED=true
fi
mv "$target" "$BACKUP_DIR/"
info "Backed up existing $label"
fi
if [[ -L "$target" ]]; then
rm "$target"
fi
mkdir -p "$(dirname "$target")"
ln -s "$source" "$target"
success "$label"
}
# ─────────────────────────────────────────────────────────────
# Symlinks from links.txt
# ─────────────────────────────────────────────────────────────
install_links() {
local current_section=""
while IFS='|' read -r section_name source target label; do
# Skip comments and empty lines
[[ "$section_name" =~ ^[[:space:]]*# ]] && continue
[[ -z "$section_name" ]] && continue
# Trim whitespace
section_name="${section_name## }"; section_name="${section_name%% }"
source="${source## }"; source="${source%% }"
target="${target## }"; target="${target%% }"
label="${label## }"; label="${label%% }"
# Print section header when it changes
if [[ "$section_name" != "$current_section" ]]; then
section "$section_name"
current_section="$section_name"
fi
backup_and_link "$DOTFILES_DIR/$source" "$HOME/$target" "$label"
done < "$DOTFILES_DIR/links.txt"
}
install_links
# ─────────────────────────────────────────────────────────────
# Cursor global rules (copy with frontmatter, not symlink)
# ─────────────────────────────────────────────────────────────
install_cursor_global_rules() {
local source="$DOTFILES_DIR/agents/GLOBAL.md"
local target="$HOME/.cursor/rules/global.mdc"
mkdir -p "$(dirname "$target")"
{
echo "---"
echo "alwaysApply: true"
echo "---"
echo ""
cat "$source"
} > "$target"
success_dim ".cursor/rules/global.mdc" "(copied)"
}
install_cursor_global_rules
# ─────────────────────────────────────────────────────────────
# Skills
# ─────────────────────────────────────────────────────────────
section "Skills"
install_skills() {
local personal_skills="$DOTFILES_DIR/agents/skills"
local external_skills="$DOTFILES_DIR/.agents/skills"
local local_skills="$DOTFILES_DIR/agents/skills.local"
local targets=(
"$HOME/.claude/skills"
"$HOME/.codex/skills"
)
local skills=()
mkdir -p "$local_skills"
for skill in "$personal_skills"/*/; do
[[ -d "$skill" ]] && skills+=("personal:$(basename "$skill")")
done
for skill in "$external_skills"/*/; do
[[ -d "$skill" ]] && skills+=("external:$(basename "$skill")")
done
for skill in "$local_skills"/*/; do
[[ -d "$skill" ]] && skills+=("local:$(basename "$skill")")
done
# Prepare target directories
for target_dir in "${targets[@]}"; do
if [[ -L "$target_dir" ]]; then
rm "$target_dir"
fi
mkdir -p "$target_dir"
done
local build_dir="$DOTFILES_DIR/agents/.build/skills"
local check="${GREEN}✓${RESET}"
local max_w=5
for skill_entry in "${skills[@]}"; do
local name="${skill_entry#*:}"
(( ${#name} > max_w )) && max_w=${#name}
done
printf " %-${max_w}s type claude codex\n" "skill"
# Sync each skill to all targets, printing status as we go
for skill_entry in "${skills[@]}"; do
local skill_type="${skill_entry%%:*}"
local skill_name="${skill_entry#*:}"
local skill_source=""
if [[ "$skill_type" == "personal" ]]; then
skill_source="$personal_skills/$skill_name/"
elif [[ "$skill_type" == "external" ]]; then
skill_source="$external_skills/$skill_name/"
else
skill_source="$local_skills/$skill_name/"
fi
for target_dir in "${targets[@]}"; do
local skill_target="$target_dir/$skill_name"
if [[ -L "$skill_target" ]]; then
rm "$skill_target"
fi
mkdir -p "$skill_target"
rsync -a --delete --exclude='skill.feedback.md' "$skill_source" "$skill_target/"
# Overwrite with cleaned version (annotations stripped)
if [[ -d "$build_dir/$skill_name" ]]; then
rsync -a "$build_dir/$skill_name/" "$skill_target/"
fi
done
local type_label="${DIM}[P]${RESET}"
[[ "$skill_type" == "external" ]] && type_label="${DIM}[E]${RESET}"
[[ "$skill_type" == "local" ]] && type_label="${DIM}[L]${RESET}"
printf " %-${max_w}s %b %b %b\n" "$skill_name" "$type_label" "$check" "$check"
done
}
install_skills
# ─────────────────────────────────────────────────────────────
# Local files (create from template if missing)
# ─────────────────────────────────────────────────────────────
section "Local"
create_from_template() {
local target="$1"
local template="$2"
local label="$3"
# Remove broken symlinks
if [[ -L "$target" ]]; then
rm "$target"
fi
if [[ ! -e "$target" ]]; then
mkdir -p "$(dirname "$target")"
if [[ -f "$template" ]]; then
cat "$template" > "$target"
success_dim "$label" "(created)"
else
warn "$label template not found"
return 1
fi
else
success_dim "$label" "(exists)"
fi
}
# Secrets file (sourced by .zprofile for API keys)
create_from_template "$HOME/.secrets" "$DOTFILES_DIR/local/secrets.template" ".secrets"
# Local environment file (sourced by .zprofile)
create_from_template "$HOME/.local/bin/env" "$DOTFILES_DIR/local/env.template" ".local/bin/env"
# ─────────────────────────────────────────────────────────────
# Cleanup old backups (keep last 10)
# ─────────────────────────────────────────────────────────────
# ─────────────────────────────────────────────────────────────
# MCP servers (Claude Code — user scope)
# ─────────────────────────────────────────────────────────────
install_claude_mcp_servers() {
section "MCP Servers (Claude Code)"
if ! command -v claude >/dev/null 2>&1; then
warn "claude CLI not found, skipping MCP setup"
return
fi
# Clean up old names
claude mcp remove --scope user figma-desktop 2>/dev/null || true
local http_servers=(
"linear|https://mcp.linear.app/mcp"
"sentry|https://mcp.sentry.dev/mcp"
"figma|http://127.0.0.1:3845/mcp"
)
for entry in "${http_servers[@]}"; do
local name="${entry%%|*}"
local url="${entry#*|}"
claude mcp add --scope user --transport http "$name" "$url" &>/dev/null || true
success "$name"
done
# stdio-based MCP servers
claude mcp add --scope user chrome-devtools -- npx -y chrome-devtools-mcp@latest --autoConnect &>/dev/null || true
success "chrome-devtools"
}
install_claude_mcp_servers
cleanup_old_backups() {
local backup_root="$HOME/.dotfiles-backup"
local keep=10
local count=$(ls -1d "$backup_root"/*/ 2>/dev/null | wc -l | tr -d ' ')
if [[ "$count" -gt "$keep" ]]; then
local to_delete=$((count - keep))
ls -1d "$backup_root"/*/ | head -n "$to_delete" | xargs rm -rf
fi
}
cleanup_old_backups
# ─────────────────────────────────────────────────────────────
# Repo-local setup (git hooks, etc.)
# ─────────────────────────────────────────────────────────────
"$DOTFILES_DIR/setup.sh"
# ─────────────────────────────────────────────────────────────
# Done
# ─────────────────────────────────────────────────────────────
echo ""
if [[ "$BACKUP_CREATED" == "true" ]]; then
printf "${GREEN}✓ Done!${RESET} ${DIM}Backups saved to: $BACKUP_DIR${RESET}\n"
else
printf "${GREEN}✓ Done!${RESET}\n"
fi
# Remind about manual steps that require sudo
if [[ ! -f /etc/paths.d/mise ]]; then
echo ""
printf "${YELLOW}Manual step needed:${RESET}\n"
printf " Add mise shims to system PATH (needed for GUI apps like Cursor to find mise-managed tools):\n"
printf " ${BOLD}echo \"\$HOME/.local/share/mise/shims\" | sudo tee /etc/paths.d/mise${RESET}\n"
fi