43 lines
1.8 KiB
PowerShell
43 lines
1.8 KiB
PowerShell
# Nudge removal. Run it with Remove.bat.
|
|
param(
|
|
[string]$SettingsPath = (Join-Path $env:USERPROFILE '.claude\settings.json')
|
|
)
|
|
$ErrorActionPreference = 'Stop'
|
|
$marker = 'ntfy.sh/nudge-'
|
|
$removed = 0
|
|
|
|
if (Test-Path -LiteralPath $SettingsPath) {
|
|
$raw = Get-Content -LiteralPath $SettingsPath -Raw
|
|
$settings = $null
|
|
try { $settings = $raw | ConvertFrom-Json } catch { }
|
|
if ($null -eq $settings) {
|
|
Write-Host 'Could not read settings.json, so nothing was changed.'
|
|
exit 1
|
|
}
|
|
if ($settings.PSObject.Properties.Name -contains 'hooks' -and
|
|
$settings.hooks.PSObject.Properties.Name -contains 'Notification') {
|
|
$keep = @()
|
|
foreach ($entry in @($settings.hooks.Notification)) {
|
|
$isNudge = $false
|
|
foreach ($h in @($entry.hooks)) {
|
|
if ($h.command -and $h.command.ToString().Contains($marker)) { $isNudge = $true }
|
|
}
|
|
if ($isNudge) { $removed++ } else { $keep += $entry }
|
|
}
|
|
if ($keep.Count -gt 0) {
|
|
$settings.hooks.Notification = @($keep)
|
|
} else {
|
|
$settings.hooks.PSObject.Properties.Remove('Notification')
|
|
}
|
|
if (@($settings.hooks.PSObject.Properties).Count -eq 0) {
|
|
$settings.PSObject.Properties.Remove('hooks')
|
|
}
|
|
$json = $settings | ConvertTo-Json -Depth 20
|
|
[System.IO.File]::WriteAllText($SettingsPath, $json, (New-Object System.Text.UTF8Encoding($false)))
|
|
}
|
|
}
|
|
$topicFile = Join-Path (Split-Path -Parent $SettingsPath) 'nudge-topic.txt'
|
|
if (Test-Path -LiteralPath $topicFile) { Remove-Item -LiteralPath $topicFile -Force }
|
|
Write-Host ('Removed ' + $removed + ' Nudge hook(s). Other settings were left alone.')
|
|
Write-Host 'You can also unsubscribe from the topic in the ntfy app.'
|