-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
72 lines (61 loc) · 2.33 KB
/
Copy pathinstall.ps1
File metadata and controls
72 lines (61 loc) · 2.33 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
[CmdletBinding()]
param(
[string]$GrokHome = $(if ($env:GROK_HOME) { $env:GROK_HOME } else { Join-Path $HOME '.grok' }),
[string]$ProfilePath = $PROFILE.CurrentUserCurrentHost
)
$ErrorActionPreference = 'Stop'
$timestamp = Get-Date -Format 'yyyyMMdd-HHmmss'
$backupDir = Join-Path $GrokHome "backups\supppergrok-$timestamp"
$promptSource = Join-Path $PSScriptRoot 'grok-4.5-unrestricted.md'
$wrapperSource = Join-Path $PSScriptRoot 'grok-wrapper.ps1'
$promptDest = Join-Path $GrokHome 'grok-4.5-unrestricted.md'
$wrapperDest = Join-Path $GrokHome 'supppergrok-wrapper.ps1'
foreach ($path in @($promptSource, $wrapperSource)) {
if (-not (Test-Path -LiteralPath $path)) {
throw "Missing source file: $path"
}
}
New-Item -ItemType Directory -Path $GrokHome -Force | Out-Null
New-Item -ItemType Directory -Path $backupDir -Force | Out-Null
New-Item -ItemType Directory -Path (Split-Path -Parent $ProfilePath) -Force | Out-Null
foreach ($path in @($promptDest, $wrapperDest, $ProfilePath)) {
if (Test-Path -LiteralPath $path) {
Copy-Item -LiteralPath $path -Destination (Join-Path $backupDir ([IO.Path]::GetFileName($path))) -Force
}
}
Copy-Item -LiteralPath $promptSource -Destination $promptDest -Force
Copy-Item -LiteralPath $wrapperSource -Destination $wrapperDest -Force
$profileText = if (Test-Path -LiteralPath $ProfilePath) {
Get-Content -LiteralPath $ProfilePath -Raw -Encoding UTF8
} else {
''
}
$profileText = [regex]::Replace(
$profileText,
'(?ms)\r?\n?# >>> SUPPPERGROK >>>.*?# <<< SUPPPERGROK <<<\r?\n?',
"`r`n"
).TrimEnd()
$escapedWrapper = $wrapperDest.Replace("'", "''")
$block = @"
# >>> SUPPPERGROK >>>
. '$escapedWrapper'
function grok { Invoke-SuppperGrok @args }
function grok-stock { Invoke-SuppperGrok '--stock-prompt' @args }
# <<< SUPPPERGROK <<<
"@
Set-Content -LiteralPath $ProfilePath -Value ($profileText + $block + "`r`n") -Encoding UTF8
$tokens = $null
$errors = $null
[void][Management.Automation.Language.Parser]::ParseFile(
$ProfilePath,
[ref]$tokens,
[ref]$errors
)
if ($errors.Count) {
throw "Profile parse failed after installation: $($errors[0].Message)"
}
Write-Output "Installed prompt: $promptDest"
Write-Output "Installed wrapper: $wrapperDest"
Write-Output "Updated profile: $ProfilePath"
Write-Output "Backup: $backupDir"
Write-Output 'Reload with: . $PROFILE'