-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·680 lines (564 loc) · 18.4 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·680 lines (564 loc) · 18.4 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
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
#!/bin/bash
#
# Claude Dev Kit - Fallback Installer
# For users without Claude Code CLI
#
# Usage: curl -fsSL https://raw.githubusercontent.com/claude-dev-kit/claude-dev-kit/main/install.sh | bash
# or: ./install.sh [--bundle minimal|standard|full] [--non-interactive]
#
set -e
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
# Configuration
CDK_VERSION="1.0.0"
CDK_REPO="https://github.com/claude-dev-kit/claude-dev-kit"
BACKUP_DIR="$HOME/.claude-dev-kit/backups/$(date +%Y-%m-%d)"
# Flags
BUNDLE=""
NON_INTERACTIVE=false
FEELING_LUCKY=false
# ------------------------------------------------------------------------------
# Utility Functions
# ------------------------------------------------------------------------------
print_banner() {
echo -e "${CYAN}"
echo " ╔═══════════════════════════════════════╗"
echo " ║ Claude Dev Kit Installer ║"
echo " ║ v${CDK_VERSION} ║"
echo " ╚═══════════════════════════════════════╝"
echo -e "${NC}"
}
log_info() {
echo -e "${BLUE}[INFO]${NC} $1"
}
log_success() {
echo -e "${GREEN}[OK]${NC} $1"
}
log_warn() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
log_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
confirm() {
if $NON_INTERACTIVE; then
return 0
fi
read -r -p "$1 [y/N] " response
case "$response" in
[yY][eE][sS]|[yY]) return 0 ;;
*) return 1 ;;
esac
}
# ------------------------------------------------------------------------------
# Dependency Checks
# ------------------------------------------------------------------------------
check_os() {
case "$(uname -s)" in
Darwin) OS="macos" ;;
Linux) OS="linux" ;;
*) log_error "Unsupported OS: $(uname -s)"; exit 1 ;;
esac
log_info "Detected OS: $OS"
}
check_command() {
command -v "$1" >/dev/null 2>&1
}
check_dependencies() {
log_info "Checking dependencies..."
local missing=()
# Required
if ! check_command git; then
missing+=("git")
fi
if ! check_command curl; then
missing+=("curl")
fi
# Optional but recommended
if ! check_command brew && [ "$OS" = "macos" ]; then
log_warn "Homebrew not found. Some components may require manual installation."
fi
if [ ${#missing[@]} -gt 0 ]; then
log_error "Missing required dependencies: ${missing[*]}"
echo ""
if [ "$OS" = "macos" ]; then
echo "Install with Homebrew:"
echo " brew install ${missing[*]}"
else
echo "Install with your package manager:"
echo " apt install ${missing[*]} # Debian/Ubuntu"
echo " dnf install ${missing[*]} # Fedora"
fi
exit 1
fi
log_success "All required dependencies found"
}
# ------------------------------------------------------------------------------
# Environment Detection
# ------------------------------------------------------------------------------
detect_environment() {
log_info "Analyzing environment..."
GREENFIELD=true
# Check for existing shell customization
if [ -d "$HOME/.oh-my-zsh" ] || [ -f "$HOME/.p10k.zsh" ]; then
log_info " Found: Custom shell setup"
GREENFIELD=false
fi
# Check for existing git config
if [ -f "$HOME/.gitconfig" ] && [ "$(wc -l < "$HOME/.gitconfig")" -gt 5 ]; then
log_info " Found: Customized git config"
GREENFIELD=false
fi
# Check for VS Code
if check_command code; then
VSCODE_EXTENSIONS=$(code --list-extensions 2>/dev/null | wc -l)
if [ "$VSCODE_EXTENSIONS" -gt 10 ]; then
log_info " Found: VS Code with $VSCODE_EXTENSIONS extensions"
GREENFIELD=false
fi
fi
# Check for existing Claude setup
if [ -d "$HOME/.claude" ]; then
log_info " Found: Existing Claude configuration"
GREENFIELD=false
fi
if $GREENFIELD; then
log_info "Environment: ${GREEN}Greenfield${NC} (fresh setup)"
MODE="greenfield"
else
log_info "Environment: ${YELLOW}Adaptation${NC} (existing setup detected)"
MODE="adaptation"
fi
}
# ------------------------------------------------------------------------------
# Bundle Selection
# ------------------------------------------------------------------------------
select_bundle() {
if [ -n "$BUNDLE" ]; then
log_info "Using bundle: $BUNDLE"
return
fi
if $NON_INTERACTIVE; then
BUNDLE="standard"
log_info "Non-interactive mode: using standard bundle"
return
fi
echo ""
echo -e "${CYAN}How would you like to proceed?${NC}"
echo ""
echo -e " ${GREEN}1) Feeling Lucky${NC} - Auto-configure everything with smart defaults"
echo " 2) minimal - Shell only (zsh, powerlevel10k, completions)"
echo " 3) standard - Shell + Editor + Git + Templates"
echo " 4) full - Everything including Quality and Memory tools"
echo " 5) custom - Choose individual components"
echo ""
read -r -p "Enter choice [1-5]: " choice
case "$choice" in
1)
BUNDLE="standard"
FEELING_LUCKY=true
echo ""
echo -e "${GREEN}Feeling Lucky mode activated!${NC}"
echo ""
;;
2) BUNDLE="minimal" ;;
3) BUNDLE="standard" ;;
4) BUNDLE="full" ;;
5) select_custom_components ;;
*) BUNDLE="standard" ;;
esac
log_info "Selected bundle: $BUNDLE"
}
select_custom_components() {
BUNDLE="custom"
COMPONENTS=()
echo ""
echo -e "${CYAN}Select components to install:${NC}"
echo ""
if confirm " Shell (zsh, powerlevel10k, aliases)?"; then
COMPONENTS+=("shell")
fi
if confirm " Editor (VS Code/Cursor settings, extensions)?"; then
COMPONENTS+=("editor")
fi
if confirm " Git (hooks, templates, conventions)?"; then
COMPONENTS+=("git")
fi
if confirm " Templates (CLAUDE.md, .claude/ directory)?"; then
COMPONENTS+=("templates")
fi
if confirm " Quality (linting, testing, review)?"; then
COMPONENTS+=("quality")
fi
if confirm " Memory (context management)?"; then
COMPONENTS+=("memory")
fi
if [ ${#COMPONENTS[@]} -eq 0 ]; then
log_warn "No components selected. Using minimal bundle."
BUNDLE="minimal"
fi
}
get_bundle_components() {
case "$BUNDLE" in
minimal) echo "shell" ;;
standard) echo "shell editor git templates" ;;
full) echo "shell editor git templates quality memory" ;;
custom) echo "${COMPONENTS[*]}" ;;
esac
}
# ------------------------------------------------------------------------------
# Backup
# ------------------------------------------------------------------------------
create_backup() {
if [ "$MODE" = "adaptation" ]; then
log_info "Creating backups in $BACKUP_DIR"
mkdir -p "$BACKUP_DIR"
# Backup shell configs
[ -f "$HOME/.zshrc" ] && cp "$HOME/.zshrc" "$BACKUP_DIR/.zshrc.bak"
[ -f "$HOME/.bashrc" ] && cp "$HOME/.bashrc" "$BACKUP_DIR/.bashrc.bak"
# Backup git configs
[ -f "$HOME/.gitconfig" ] && cp "$HOME/.gitconfig" "$BACKUP_DIR/.gitconfig.bak"
[ -f "$HOME/.gitmessage" ] && cp "$HOME/.gitmessage" "$BACKUP_DIR/.gitmessage.bak"
# Backup VS Code settings
if [ "$OS" = "macos" ]; then
VSCODE_DIR="$HOME/Library/Application Support/Code/User"
else
VSCODE_DIR="$HOME/.config/Code/User"
fi
[ -f "$VSCODE_DIR/settings.json" ] && cp "$VSCODE_DIR/settings.json" "$BACKUP_DIR/vscode-settings.json.bak"
log_success "Backups created"
fi
}
# ------------------------------------------------------------------------------
# Component Installers
# ------------------------------------------------------------------------------
install_shell() {
log_info "Installing Shell component..."
# Install Oh My Zsh if not present
if [ ! -d "$HOME/.oh-my-zsh" ]; then
log_info " Installing Oh My Zsh..."
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended
else
log_info " Oh My Zsh already installed"
fi
# Install Powerlevel10k
P10K_DIR="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k"
if [ ! -d "$P10K_DIR" ]; then
log_info " Installing Powerlevel10k..."
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git "$P10K_DIR"
else
log_info " Updating Powerlevel10k..."
cd "$P10K_DIR" && git pull --quiet
fi
# Install fonts
log_info " Installing MesloLGS NF fonts..."
if [ "$OS" = "macos" ]; then
FONT_DIR="$HOME/Library/Fonts"
else
FONT_DIR="$HOME/.local/share/fonts"
fi
mkdir -p "$FONT_DIR"
for style in Regular Bold Italic "Bold Italic"; do
FONT_FILE="MesloLGS NF ${style}.ttf"
FONT_URL="https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20${style// /%20}.ttf"
if [ ! -f "$FONT_DIR/$FONT_FILE" ]; then
curl -sL -o "$FONT_DIR/$FONT_FILE" "$FONT_URL"
fi
done
[ "$OS" = "linux" ] && fc-cache -f 2>/dev/null
# Install plugins
ZSH_CUSTOM="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}"
if [ ! -d "$ZSH_CUSTOM/plugins/zsh-autosuggestions" ]; then
log_info " Installing zsh-autosuggestions..."
git clone --quiet https://github.com/zsh-users/zsh-autosuggestions "$ZSH_CUSTOM/plugins/zsh-autosuggestions"
fi
if [ ! -d "$ZSH_CUSTOM/plugins/zsh-syntax-highlighting" ]; then
log_info " Installing zsh-syntax-highlighting..."
git clone --quiet https://github.com/zsh-users/zsh-syntax-highlighting "$ZSH_CUSTOM/plugins/zsh-syntax-highlighting"
fi
# Update .zshrc
if ! grep -q "powerlevel10k" "$HOME/.zshrc" 2>/dev/null; then
log_info " Configuring .zshrc..."
sed -i.bak 's/ZSH_THEME=".*"/ZSH_THEME="powerlevel10k\/powerlevel10k"/' "$HOME/.zshrc"
fi
# Add plugins
if ! grep -q "zsh-autosuggestions" "$HOME/.zshrc" 2>/dev/null; then
sed -i.bak 's/plugins=(git)/plugins=(git zsh-autosuggestions zsh-syntax-highlighting)/' "$HOME/.zshrc"
fi
# Add Claude aliases
if ! grep -q "Claude Dev Kit" "$HOME/.zshrc" 2>/dev/null; then
cat >> "$HOME/.zshrc" << 'EOF'
# Claude Dev Kit aliases
alias cc='claude'
alias ccp='claude -p'
alias ccc='claude --continue'
alias ccr='claude --resume'
EOF
fi
log_success "Shell component installed"
}
install_editor() {
log_info "Installing Editor component..."
# Detect editor
EDITOR_CMD=""
if check_command cursor; then
EDITOR_CMD="cursor"
log_info " Detected: Cursor"
elif check_command code; then
EDITOR_CMD="code"
log_info " Detected: VS Code"
else
log_warn " No supported editor found (VS Code or Cursor)"
return
fi
# Install extensions
log_info " Installing extensions..."
$EDITOR_CMD --install-extension eamodio.gitlens 2>/dev/null || true
$EDITOR_CMD --install-extension usernamehw.errorlens 2>/dev/null || true
$EDITOR_CMD --install-extension esbenp.prettier-vscode 2>/dev/null || true
$EDITOR_CMD --install-extension dbaeumer.vscode-eslint 2>/dev/null || true
$EDITOR_CMD --install-extension streetsidesoftware.code-spell-checker 2>/dev/null || true
# Configure settings
if [ "$OS" = "macos" ]; then
if [ "$EDITOR_CMD" = "cursor" ]; then
SETTINGS_DIR="$HOME/Library/Application Support/Cursor/User"
else
SETTINGS_DIR="$HOME/Library/Application Support/Code/User"
fi
else
if [ "$EDITOR_CMD" = "cursor" ]; then
SETTINGS_DIR="$HOME/.config/Cursor/User"
else
SETTINGS_DIR="$HOME/.config/Code/User"
fi
fi
mkdir -p "$SETTINGS_DIR"
# Only add settings if not already configured
if [ ! -f "$SETTINGS_DIR/settings.json" ]; then
log_info " Creating settings.json..."
cat > "$SETTINGS_DIR/settings.json" << 'EOF'
{
"editor.formatOnSave": true,
"editor.bracketPairColorization.enabled": true,
"editor.minimap.enabled": false,
"terminal.integrated.fontFamily": "MesloLGS NF",
"files.autoSave": "onFocusChange",
"files.trimTrailingWhitespace": true,
"files.insertFinalNewline": true,
"errorLens.enabledDiagnosticLevels": ["error", "warning"],
"gitlens.codeLens.enabled": false,
"gitlens.currentLine.enabled": true
}
EOF
else
log_info " Settings.json exists, skipping (use skill for merge)"
fi
log_success "Editor component installed"
}
install_git() {
log_info "Installing Git component..."
# Commit template
log_info " Creating commit template..."
cat > "$HOME/.gitmessage" << 'EOF'
# <type>(<scope>): <subject>
#
# Types: feat, fix, docs, style, refactor, test, chore
#
# Co-Authored-By: Claude <noreply@anthropic.com>
EOF
git config --global commit.template "$HOME/.gitmessage"
# Global gitignore
log_info " Creating global gitignore..."
cat > "$HOME/.gitignore_global" << 'EOF'
.DS_Store
*.swp
*.swo
.idea/
.vscode/
.claude-context/
*.claude-session
.env.local
.env.*.local
EOF
git config --global core.excludesfile "$HOME/.gitignore_global"
# Hooks
log_info " Installing git hooks..."
HOOKS_DIR="$HOME/.config/git/hooks"
mkdir -p "$HOOKS_DIR"
cat > "$HOOKS_DIR/commit-msg" << 'EOF'
#!/bin/bash
commit_regex='^(feat|fix|docs|style|refactor|test|chore|build|ci)(\(.+\))?: .{1,50}'
if ! grep -qE "$commit_regex" "$1"; then
echo "Error: Commit message doesn't follow conventional format."
echo "Expected: <type>(<scope>): <subject>"
exit 1
fi
EOF
chmod +x "$HOOKS_DIR/commit-msg"
git config --global core.hooksPath "$HOOKS_DIR"
# Aliases
log_info " Adding git aliases..."
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.st status
git config --global alias.wip 'commit -am "wip: work in progress"'
git config --global alias.undo 'reset --soft HEAD~1'
log_success "Git component installed"
}
install_templates() {
log_info "Installing Templates component..."
# Create .claude directory structure
log_info " Creating .claude/ template..."
mkdir -p "$HOME/.claude-dev-kit/templates/.claude/commands"
cat > "$HOME/.claude-dev-kit/templates/.claude/commands/test.md" << 'EOF'
Run all tests and report results. If tests fail, analyze the failure and suggest fixes.
EOF
cat > "$HOME/.claude-dev-kit/templates/.claude/commands/review.md" << 'EOF'
Review recent changes for code quality, bugs, performance, and security.
Provide specific, actionable feedback.
EOF
# Create CLAUDE.md template
cat > "$HOME/.claude-dev-kit/templates/CLAUDE.md" << 'EOF'
# Project Context
## Overview
[Brief description]
## Tech Stack
- [List technologies]
## Directory Structure
- [Key directories]
## Commands
- [Common commands]
## Conventions
- [Naming and style]
## Important Notes
- [Critical info]
EOF
log_info " Templates saved to ~/.claude-dev-kit/templates/"
log_info " Copy to your project: cp -r ~/.claude-dev-kit/templates/.claude ."
log_success "Templates component installed"
}
install_quality() {
log_info "Installing Quality component..."
log_warn " Quality component requires per-project setup."
log_info " Use Claude Code with 'setup-cdk-quality' skill for full installation."
log_success "Quality component noted (manual setup required)"
}
install_memory() {
log_info "Installing Memory component..."
log_warn " Memory component requires Claude Code."
log_info " Use Claude Code with 'setup-cdk-memory' skill for full installation."
log_success "Memory component noted (manual setup required)"
}
# ------------------------------------------------------------------------------
# Main Installation
# ------------------------------------------------------------------------------
install_components() {
COMPONENTS_TO_INSTALL=$(get_bundle_components)
log_info "Installing components: $COMPONENTS_TO_INSTALL"
echo ""
for component in $COMPONENTS_TO_INSTALL; do
case "$component" in
shell) install_shell ;;
editor) install_editor ;;
git) install_git ;;
templates) install_templates ;;
quality) install_quality ;;
memory) install_memory ;;
esac
echo ""
done
}
print_summary() {
echo ""
echo -e "${GREEN}════════════════════════════════════════${NC}"
echo -e "${GREEN} Installation Complete!${NC}"
echo -e "${GREEN}════════════════════════════════════════${NC}"
echo ""
echo "Installed components:"
for component in $(get_bundle_components); do
echo -e " ${GREEN}✓${NC} $component"
done
echo ""
if [ "$MODE" = "adaptation" ]; then
echo "Backups saved to: $BACKUP_DIR"
echo ""
fi
echo "Next steps:"
echo " 1. Restart your terminal (or run: source ~/.zshrc)"
echo " 2. Run 'p10k configure' to set up your prompt"
echo " 3. Set terminal font to 'MesloLGS NF'"
echo ""
echo "For the best experience, install Claude Code:"
echo " npm install -g @anthropic-ai/claude-code"
echo ""
echo "Then run: claude 'setup-claude-dev-kit'"
echo ""
}
# ------------------------------------------------------------------------------
# Argument Parsing
# ------------------------------------------------------------------------------
parse_args() {
while [[ $# -gt 0 ]]; do
case "$1" in
--bundle)
BUNDLE="$2"
shift 2
;;
--feeling-lucky)
FEELING_LUCKY=true
BUNDLE="standard"
NON_INTERACTIVE=true
shift
;;
--non-interactive)
NON_INTERACTIVE=true
shift
;;
--help|-h)
echo "Usage: $0 [options]"
echo ""
echo "Options:"
echo " --feeling-lucky Auto-configure everything with smart defaults"
echo " --bundle <name> Install specific bundle (minimal, standard, full)"
echo " --non-interactive Skip prompts, use defaults"
echo " --help Show this help"
exit 0
;;
*)
log_error "Unknown option: $1"
exit 1
;;
esac
done
}
# ------------------------------------------------------------------------------
# Entry Point
# ------------------------------------------------------------------------------
main() {
parse_args "$@"
print_banner
check_os
check_dependencies
# Ask bundle selection first (includes "Feeling Lucky" option)
select_bundle
detect_environment
# Skip confirmation if Feeling Lucky mode
echo ""
if [ "$MODE" = "adaptation" ] && ! $NON_INTERACTIVE && ! $FEELING_LUCKY; then
if ! confirm "Existing setup detected. Continue with adaptation mode?"; then
log_info "Installation cancelled."
exit 0
fi
fi
create_backup
echo ""
install_components
print_summary
}
main "$@"