Fix Gist setup and first-run bootstrap

This commit is contained in:
2026-07-29 17:43:26 +08:00
parent 13cf327f48
commit f19466a5df
9 changed files with 189 additions and 65 deletions
+30 -14
View File
@@ -48,18 +48,20 @@ function Write-Atomic([string]$Path, [string]$Contents) {
}
Require-Command "node" "winget install OpenJS.NodeJS.LTS"
Require-Command "gh" "winget install GitHub.cli"
& gh auth status *> $null
if ($LASTEXITCODE -ne 0) {
Write-Host "GitHub authentication is required."
& gh auth login
if ($LASTEXITCODE -ne 0) { throw "GitHub authentication failed." }
if (-not $env:ZED_SETTINGS_BUNDLE_PATH) {
Require-Command "gh" "winget install GitHub.cli"
Remove-Item Env:GH_TOKEN,Env:GITHUB_TOKEN -ErrorAction SilentlyContinue
& gh auth status *> $null
if ($LASTEXITCODE -ne 0) {
Write-Host "GitHub authentication is required."
& gh auth login
if ($LASTEXITCODE -ne 0) { throw "GitHub authentication failed." }
}
}
$entered = if ($env:ZED_SETTINGS_GIST_ID) { $env:ZED_SETTINGS_GIST_ID } else { Read-Host "GitHub Gist ID or full URL" }
$gistId = Get-GistId $entered
$entered = if ($env:ZED_SETTINGS_GIST_ID) { $env:ZED_SETTINGS_GIST_ID } else { Read-Host "GitHub Gist ID or URL (leave blank to create a new Secret Gist)" }
if ($env:ZED_SETTINGS_BUNDLE_PATH) {
$gistId = Get-GistId $entered
$bundleSource = [IO.File]::ReadAllText($env:ZED_SETTINGS_BUNDLE_PATH, [Text.Encoding]::UTF8)
} else {
$token = (& gh auth token).Trim()
@@ -70,11 +72,25 @@ if ($env:ZED_SETTINGS_BUNDLE_PATH) {
"User-Agent" = "zed-settings-bootstrap"
"X-GitHub-Api-Version" = "2022-11-28"
}
$gist = Invoke-RestMethod -Uri "https://api.github.com/gists/$gistId" -Headers $headers
$remoteFile = $gist.files.$bundleName
if (-not $remoteFile) { throw "Gist $gistId does not contain $bundleName." }
if ($remoteFile.truncated) { throw "$bundleName is too large for the Gist API response." }
$bundleSource = [string]$remoteFile.content
if ([string]::IsNullOrWhiteSpace($entered)) {
$seedUrl = "https://git.okk.cool/purp1e/zed-sync/raw/branch/master/zed-settings-sync.json"
$bundleSource = (Invoke-WebRequest -UseBasicParsing -Uri $seedUrl).Content
$payload = @{
description = "Zed settings sync"
public = $false
files = @{ $bundleName = @{ content = $bundleSource } }
} | ConvertTo-Json -Depth 5
$created = Invoke-RestMethod -Method Post -Uri "https://api.github.com/gists" -Headers $headers -ContentType "application/json" -Body ([Text.Encoding]::UTF8.GetBytes($payload))
$gistId = $created.id
Write-Host "Created Secret Gist: $($created.html_url)"
} else {
$gistId = Get-GistId $entered
$gist = Invoke-RestMethod -Uri "https://api.github.com/gists/$gistId" -Headers $headers
$remoteFile = $gist.files.$bundleName
if (-not $remoteFile) { throw "Gist $gistId does not contain $bundleName." }
if ($remoteFile.truncated) { throw "$bundleName is too large for the Gist API response." }
$bundleSource = [string]$remoteFile.content
}
}
try {