-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
102 lines (86 loc) · 3.46 KB
/
install.ps1
File metadata and controls
102 lines (86 loc) · 3.46 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
#Requires -Version 5.1
<#
.SYNOPSIS
Install Claude Code rules, agents, and skills.
.DESCRIPTION
Copies common rules, language-specific rules, agents, and skills into ~/.claude/.
.PARAMETER Languages
One or more language names (e.g., golang, java, terraform).
.PARAMETER All
Install all available language rules.
.EXAMPLE
.\install.ps1 golang
.\install.ps1 golang java terraform
.\install.ps1 -All
#>
param(
[Parameter(Position = 0, ValueFromRemainingArguments = $true)]
[string[]]$Languages,
[switch]$All
)
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$RulesDir = Join-Path $ScriptDir 'rules'
$AgentsDir = Join-Path $ScriptDir 'agents'
$SkillsDir = Join-Path $ScriptDir 'skills'
$DestDir = Join-Path $HOME '.claude' 'rules'
# Discover available languages (subdirs of rules/ excluding common)
$AvailableLanguages = Get-ChildItem -Path $RulesDir -Directory |
Where-Object { $_.Name -ne 'common' } |
ForEach-Object { $_.Name }
# --- Usage ---
if (-not $All -and (-not $Languages -or $Languages.Count -eq 0)) {
Write-Host "Usage: .\install.ps1 <language> [<language> ...] [-All]"
Write-Host ""
Write-Host "Available languages:"
foreach ($lang in $AvailableLanguages) {
Write-Host " - $lang"
}
exit 1
}
# Resolve --All to all available languages
if ($All) {
$Languages = $AvailableLanguages
}
# Warn if destination already exists
if ((Test-Path $DestDir) -and (Get-ChildItem -Path $DestDir -ErrorAction SilentlyContinue)) {
Write-Host "Note: $DestDir/ already exists. Existing files will be overwritten."
Write-Host " Back up any local customizations before proceeding."
}
# --- Install common rules ---
$CommonDest = Join-Path $DestDir 'common'
Write-Host "Installing common rules -> $CommonDest/"
New-Item -ItemType Directory -Path $CommonDest -Force | Out-Null
Copy-Item -Path (Join-Path $RulesDir 'common' '*') -Destination $CommonDest -Recurse -Force
# --- Install each requested language ---
foreach ($lang in $Languages) {
# Validate language name to prevent path traversal
if ($lang -notmatch '^[a-zA-Z0-9_-]+$') {
Write-Warning "Invalid language name '$lang'. Only alphanumeric, dash, and underscore allowed."
continue
}
$LangDir = Join-Path $RulesDir $lang
if (-not (Test-Path $LangDir)) {
Write-Warning "rules/$lang/ does not exist, skipping."
continue
}
$LangDest = Join-Path $DestDir $lang
Write-Host "Installing $lang rules -> $LangDest/"
New-Item -ItemType Directory -Path $LangDest -Force | Out-Null
Copy-Item -Path (Join-Path $LangDir '*') -Destination $LangDest -Recurse -Force
}
# --- Install agents ---
$AgentsDest = Join-Path $HOME '.claude' 'agents'
Write-Host "Installing agents -> $AgentsDest/"
New-Item -ItemType Directory -Path $AgentsDest -Force | Out-Null
Copy-Item -Path (Join-Path $AgentsDir '*.md') -Destination $AgentsDest -Force
# --- Install skills (preserve subdirectory structure) ---
$SkillsDest = Join-Path $HOME '.claude' 'skills'
Write-Host "Installing skills -> $SkillsDest/"
foreach ($skillDir in (Get-ChildItem -Path $SkillsDir -Directory)) {
$SkillDestDir = Join-Path $SkillsDest $skillDir.Name
New-Item -ItemType Directory -Path $SkillDestDir -Force | Out-Null
Copy-Item -Path (Join-Path $skillDir.FullName 'SKILL.md') -Destination $SkillDestDir -Force
}
Write-Host "Done. Installed to ~/.claude/ (rules, agents, skills)."