-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.ps1
More file actions
119 lines (106 loc) · 4.45 KB
/
Copy pathdeploy.ps1
File metadata and controls
119 lines (106 loc) · 4.45 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
# deploy.ps1 - Install/update ClaudeCM runtime files on Windows.
#
# Idempotent: safe to re-run after every `git pull`. Byte-identical files
# are skipped, changed files get a timestamped backup in ~/.claudecm/backup/
# before being overwritten.
#
# Files this script owns:
# ~/.claudecm/claudecm-powershell.ps1
# ~/.claudecm/extract-skeleton.mjs
# ~/.claudecm/bgcolor.ps1
# ~/.claudecm/register-late-guid.ps1
# ~/bin/bgcolor.cmd (generated shim; not in repo)
#
# Files this script does NOT touch (they belong to you):
# $PROFILE (initial setup only, per docs/install.md)
# ~/.claudecm/sessions.txt, machine-name.txt, notes/, backup/
#
# Usage (from the repo root):
# .\deploy.ps1
$ErrorActionPreference = 'Stop'
$repoRoot = Split-Path -Parent $PSCommandPath
$cmDir = "$env:USERPROFILE\.claudecm"
$binDir = "$env:USERPROFILE\bin"
$backupDir = "$cmDir\backup"
foreach ($d in @($cmDir, $backupDir, $binDir)) {
if (-not (Test-Path $d)) { New-Item -ItemType Directory -Path $d -Force | Out-Null }
}
$stamp = Get-Date -Format 'yyyyMMdd-HHmmss'
$runtimeScript = Join-Path $cmDir 'claudecm-powershell.ps1'
# Snapshot the personal-preference tweak state BEFORE we overwrite anything.
# The commented-out line is the repo default; uncommented is a personal tweak.
$hadTweak = $false
if (Test-Path $runtimeScript) {
$hadTweak = (Get-Content $runtimeScript -Raw) -match '(?m)^\s*\$env:CLAUDE_CODE_ENABLE_PROMPT_SUGGESTION\s*=\s*"0"'
}
$claudecmFiles = @(
'claudecm-powershell.ps1',
'extract-skeleton.mjs',
'bgcolor.ps1',
'register-late-guid.ps1'
)
$copied = @()
$skipped = @()
foreach ($f in $claudecmFiles) {
$src = Join-Path $repoRoot $f
$dst = Join-Path $cmDir $f
if (-not (Test-Path $src)) {
Write-Host " MISSING in repo: $f (skipped)" -ForegroundColor Yellow
continue
}
if (Test-Path $dst) {
if ((Get-FileHash $src -Algorithm SHA256).Hash -eq (Get-FileHash $dst -Algorithm SHA256).Hash) {
$skipped += $f
continue
}
Copy-Item -LiteralPath $dst -Destination (Join-Path $backupDir "$f.$stamp.pre-deploy") -Force
}
Copy-Item -LiteralPath $src -Destination $dst -Force
$copied += $f
}
# bgcolor.cmd shim so plain `bgcolor` works from Command Prompt and File
# Explorer's Run dialog. Generated, not in the repo.
$shimPath = Join-Path $binDir 'bgcolor.cmd'
$shimBody = "@echo off`r`npowershell.exe -NoProfile -ExecutionPolicy Bypass -File `"%USERPROFILE%\.claudecm\bgcolor.ps1`" %*`r`n"
$existing = if (Test-Path $shimPath) { Get-Content $shimPath -Raw } else { '' }
if ($existing -ne $shimBody) {
if (Test-Path $shimPath) {
Copy-Item -LiteralPath $shimPath -Destination (Join-Path $backupDir "bgcolor.cmd.$stamp.pre-deploy") -Force
}
Set-Content -LiteralPath $shimPath -Value $shimBody -NoNewline
$copied += 'bin\bgcolor.cmd'
}
Write-Host ""
if ($copied.Count -gt 0) {
Write-Host " Deployed:" -ForegroundColor Green
$copied | ForEach-Object { Write-Host " - $_" }
} else {
Write-Host " Nothing to do -- all files already match the repo." -ForegroundColor Green
}
if ($skipped.Count -gt 0) {
Write-Host " Unchanged: $($skipped -join ', ')" -ForegroundColor DarkGray
}
# If the tweak was set before and got clobbered, tell the user.
if ($hadTweak) {
$stillHasTweak = (Get-Content $runtimeScript -Raw) -match '(?m)^\s*\$env:CLAUDE_CODE_ENABLE_PROMPT_SUGGESTION\s*=\s*"0"'
if (-not $stillHasTweak) {
Write-Host ""
Write-Host " NOTE: CLAUDE_CODE_ENABLE_PROMPT_SUGGESTION=`"0`" was active in your runtime" -ForegroundColor Yellow
Write-Host " copy and is now commented out again (repo default)." -ForegroundColor Yellow
Write-Host " Uncomment the line near the top of $runtimeScript" -ForegroundColor Yellow
Write-Host " to restore, or see REVERT-CLAUDECM.md." -ForegroundColor Yellow
}
}
# The statusline is configured too, because a pull alone leaves the laptop with
# claude-hud's upstream defaults, which hide the weekly usage bar below 80%.
# Separate script: its config path must be absolute and machine-specific, so it
# cannot simply be a file in the repo. See docs/statusline.md.
$hudScript = Join-Path $PSScriptRoot 'configure-hud.ps1'
if (Test-Path $hudScript) {
Write-Host ""
& $hudScript
}
Write-Host ""
Write-Host " Backups (if written): $backupDir\*.pre-deploy" -ForegroundColor DarkGray
Write-Host " Open a new PowerShell tab to pick up changes." -ForegroundColor DarkGray
Write-Host ""