-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathspawn-copilot.ps1
More file actions
32 lines (26 loc) · 1.13 KB
/
Copy pathspawn-copilot.ps1
File metadata and controls
32 lines (26 loc) · 1.13 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
param(
[Parameter(Mandatory = $true)]
[string]$Folder
)
$resolvedFolder = (Resolve-Path -LiteralPath $Folder).Path
$configHome = if ($env:COPILOT_HOME) { $env:COPILOT_HOME } else { Join-Path $HOME '.copilot' }
$configPath = Join-Path $configHome 'config.json'
if (-not (Test-Path -LiteralPath $configHome)) {
New-Item -ItemType Directory -Path $configHome -Force | Out-Null
}
$config = @{}
if (Test-Path -LiteralPath $configPath) {
$config = Get-Content -Raw -LiteralPath $configPath | ConvertFrom-Json -AsHashtable
if ($null -eq $config) {
$config = @{}
}
}
$trustedFolders = @($config.trustedFolders)
if ($trustedFolders -notcontains $resolvedFolder) {
$trustedFolders += $resolvedFolder
}
$config.trustedFolders = $trustedFolders
$config | ConvertTo-Json -Depth 100 | Set-Content -LiteralPath $configPath -Encoding utf8
$escapedFolder = $resolvedFolder.Replace("'", "''")
$command = "Set-Location -LiteralPath '$escapedFolder'; copilot --add-dir '$escapedFolder' --yolo --autopilot"
Start-Process -FilePath "pwsh" -ArgumentList @("-NoExit", "-Command", $command) -WorkingDirectory $resolvedFolder | Out-Null