diff --git a/README.ko.md b/README.ko.md index 545768d..67abb07 100644 --- a/README.ko.md +++ b/README.ko.md @@ -50,11 +50,11 @@ Codigest는 AI 모델을 호출하지 않습니다. 모델에게 보낼 자료 ## 설치 -빌드된 바이너리를 설치합니다. Python이 필요 없습니다. Windows (PowerShell): +빌드된 바이너리를 설치합니다. Python이 필요 없습니다. Windows (cmd 또는 PowerShell): ```powershell -irm https://raw.githubusercontent.com/NaNIsaac/codigest/main/install.ps1 | iex +powershell -ExecutionPolicy Bypass -c "irm -useb https://raw.githubusercontent.com/NaNIsaac/codigest/main/install.ps1 | iex" ``` Linux, macOS, Termux: diff --git a/README.md b/README.md index 7dc3e71..ca31c13 100644 --- a/README.md +++ b/README.md @@ -55,11 +55,11 @@ your machine. ## Install -Prebuilt binary, no Python needed. Windows (PowerShell): +Prebuilt binary, no Python needed. Windows (cmd or PowerShell): ```powershell -irm https://raw.githubusercontent.com/NaNIsaac/codigest/main/install.ps1 | iex +powershell -ExecutionPolicy Bypass -c "irm -useb https://raw.githubusercontent.com/NaNIsaac/codigest/main/install.ps1 | iex" ``` Linux, macOS and Termux: diff --git a/install.ps1 b/install.ps1 index f7ff671..719ab8c 100644 --- a/install.ps1 +++ b/install.ps1 @@ -1,74 +1,78 @@ # Installs cdg, the Codigest binary, from a GitHub release. # -# irm https://raw.githubusercontent.com/NaNIsaac/codigest/main/install.ps1 | iex +# powershell -ExecutionPolicy Bypass -c "irm -useb https://raw.githubusercontent.com/NaNIsaac/codigest/main/install.ps1 | iex" # # CDG_VERSION=0.12.1 picks a release instead of the latest one. CDG_INSTALL_DIR picks the # folder; the default one is added to the user PATH, a chosen one is left to you. # Running it again replaces the installed binary. -$ErrorActionPreference = 'Stop' -$ProgressPreference = 'SilentlyContinue' +# irm | iex runs this in your shell's scope; the script block keeps its settings and variables +# out of it. Only the PATH changes are meant to stay. +& { + $ErrorActionPreference = 'Stop' + $ProgressPreference = 'SilentlyContinue' -$repo = 'NaNIsaac/codigest' -# Only an x64 build exists; Windows on ARM runs it under emulation. -$target = 'x86_64-pc-windows-msvc' + $repo = 'NaNIsaac/codigest' + # Only an x64 build exists; Windows on ARM runs it under emulation. + $target = 'x86_64-pc-windows-msvc' -if ($env:CDG_VERSION) { - $tag = 'rust-v' + ($env:CDG_VERSION -replace '^(rust-)?v', '') - $release = Invoke-RestMethod "https://api.github.com/repos/$repo/releases/tags/$tag" -} else { - # not releases/latest: a GitHub release for a Python v* tag would take that spot - $release = (Invoke-RestMethod "https://api.github.com/repos/$repo/releases?per_page=30") | - Where-Object { -not $_.draft -and -not $_.prerelease -and $_.tag_name -like 'rust-v*' } | - Select-Object -First 1 - if (-not $release) { throw "No rust-v* release found in $repo." } -} -$asset = $release.assets | Where-Object { $_.name -like "codigest-*-$target.zip" } | Select-Object -First 1 -if (-not $asset) { - throw "Release $($release.tag_name) has no $target archive." -} + if ($env:CDG_VERSION) { + $tag = 'rust-v' + ($env:CDG_VERSION -replace '^(rust-)?v', '') + $release = Invoke-RestMethod "https://api.github.com/repos/$repo/releases/tags/$tag" + } else { + # not releases/latest: a GitHub release for a Python v* tag would take that spot + $release = (Invoke-RestMethod "https://api.github.com/repos/$repo/releases?per_page=30") | + Where-Object { -not $_.draft -and -not $_.prerelease -and $_.tag_name -like 'rust-v*' } | + Select-Object -First 1 + if (-not $release) { throw "No rust-v* release found in $repo." } + } + $asset = $release.assets | Where-Object { $_.name -like "codigest-*-$target.zip" } | Select-Object -First 1 + if (-not $asset) { + throw "Release $($release.tag_name) has no $target archive." + } -$custom = [bool]$env:CDG_INSTALL_DIR -$dir = if ($custom) { $env:CDG_INSTALL_DIR } else { Join-Path $env:LOCALAPPDATA 'Programs\codigest' } + $custom = [bool]$env:CDG_INSTALL_DIR + $dir = if ($custom) { $env:CDG_INSTALL_DIR } else { Join-Path $env:LOCALAPPDATA 'Programs\codigest' } -$work = Join-Path ([IO.Path]::GetTempPath()) ("cdg-install-" + [guid]::NewGuid()) -New-Item -ItemType Directory -Force $work | Out-Null -try { - $zip = Join-Path $work $asset.name - Write-Host "Downloading $($asset.name)" - Invoke-WebRequest $asset.browser_download_url -OutFile $zip - # GitHub records each asset's SHA-256 as "sha256:" - if ("$($asset.digest)" -notmatch '^sha256:([0-9a-f]{64})$') { - throw "Release $($release.tag_name) has no SHA-256 digest for $($asset.name)." + $work = Join-Path ([IO.Path]::GetTempPath()) ("cdg-install-" + [guid]::NewGuid()) + New-Item -ItemType Directory -Force $work | Out-Null + try { + $zip = Join-Path $work $asset.name + Write-Host "Downloading $($asset.name)" + Invoke-WebRequest $asset.browser_download_url -OutFile $zip + # GitHub records each asset's SHA-256 as "sha256:" + if ("$($asset.digest)" -notmatch '^sha256:([0-9a-f]{64})$') { + throw "Release $($release.tag_name) has no SHA-256 digest for $($asset.name)." + } + $fs = [IO.File]::OpenRead($zip) + try { $got = -join ([Security.Cryptography.SHA256]::Create().ComputeHash($fs) | ForEach-Object { $_.ToString('x2') }) } finally { $fs.Dispose() } + if ($got -ne $Matches[1]) { throw "Checksum mismatch for $($asset.name): expected $($Matches[1]), got $got." } + Expand-Archive $zip $work + $exe = Get-ChildItem $work -Recurse -Filter cdg.exe | Select-Object -First 1 + New-Item -ItemType Directory -Force $dir | Out-Null + Copy-Item $exe.FullName (Join-Path $dir 'cdg.exe') -Force + } finally { + Remove-Item $work -Recurse -Force -ErrorAction SilentlyContinue } - $fs = [IO.File]::OpenRead($zip) - try { $got = -join ([Security.Cryptography.SHA256]::Create().ComputeHash($fs) | ForEach-Object { $_.ToString('x2') }) } finally { $fs.Dispose() } - if ($got -ne $Matches[1]) { throw "Checksum mismatch for $($asset.name): expected $($Matches[1]), got $got." } - Expand-Archive $zip $work - $exe = Get-ChildItem $work -Recurse -Filter cdg.exe | Select-Object -First 1 - New-Item -ItemType Directory -Force $dir | Out-Null - Copy-Item $exe.FullName (Join-Path $dir 'cdg.exe') -Force -} finally { - Remove-Item $work -Recurse -Force -ErrorAction SilentlyContinue -} -$userPath = [Environment]::GetEnvironmentVariable('Path', 'User') -$onPath = ($userPath -split ';') -contains $dir -if (-not $custom -and -not $onPath) { - [Environment]::SetEnvironmentVariable('Path', ($userPath.TrimEnd(';') + ";$dir").TrimStart(';'), 'User') - Write-Host "Added $dir to your user PATH." -} -if (-not (($env:Path -split ';') -contains $dir)) { - $env:Path = "$env:Path;$dir" -} + $userPath = [Environment]::GetEnvironmentVariable('Path', 'User') + $onPath = ($userPath -split ';') -contains $dir + if (-not $custom -and -not $onPath) { + [Environment]::SetEnvironmentVariable('Path', ($userPath.TrimEnd(';') + ";$dir").TrimStart(';'), 'User') + Write-Host "Added $dir to your user PATH." + } + if (-not (($env:Path -split ';') -contains $dir)) { + $env:Path = "$env:Path;$dir" + } -Write-Host "Installed $(& (Join-Path $dir 'cdg.exe') --version) to $dir" -# The Python package (uv tool, pipx) also provides cdg; whichever is first on PATH runs. -$first = Get-Command cdg -CommandType Application -ErrorAction SilentlyContinue | Select-Object -First 1 -if ($first -and -not ((Split-Path $first.Source) -ieq $dir.TrimEnd('\'))) { - Write-Warning "cdg in new shells is $($first.Source) ($(& $first.Source --version)), not this install. Remove one (e.g. 'uv tool uninstall codigest') or put $dir earlier on PATH." -} -if ($custom -and -not $onPath) { - Write-Host "Add $dir to PATH to run cdg from anywhere." + Write-Host "Installed $(& (Join-Path $dir 'cdg.exe') --version) to $dir" + # The Python package (uv tool, pipx) also provides cdg; whichever is first on PATH runs. + $first = Get-Command cdg -CommandType Application -ErrorAction SilentlyContinue | Select-Object -First 1 + if ($first -and -not ((Split-Path $first.Source) -ieq $dir.TrimEnd('\'))) { + Write-Warning "cdg in new shells is $($first.Source) ($(& $first.Source --version)), not this install. Remove one (e.g. 'uv tool uninstall codigest') or put $dir earlier on PATH." + } + if ($custom -and -not $onPath) { + Write-Host "Add $dir to PATH to run cdg from anywhere." + } + Write-Host "Next: cdg term install (captures command output in new shells)" } -Write-Host "Next: cdg term install (captures command output in new shells)" diff --git a/install.sh b/install.sh index 1e7c5a1..f8298b6 100644 --- a/install.sh +++ b/install.sh @@ -30,7 +30,7 @@ else Darwin-x86_64) target=x86_64-apple-darwin ;; Darwin-arm64) target=aarch64-apple-darwin ;; MINGW* | MSYS* | CYGWIN*) - echo "On Windows, run in PowerShell: irm https://raw.githubusercontent.com/$repo/main/install.ps1 | iex" >&2 + echo "On Windows, run in cmd or PowerShell: powershell -ExecutionPolicy Bypass -c \"irm -useb https://raw.githubusercontent.com/$repo/main/install.ps1 | iex\"" >&2 exit 1 ;; *) diff --git a/rust/README.md b/rust/README.md index e61971f..4a2c0ab 100644 --- a/rust/README.md +++ b/rust/README.md @@ -13,7 +13,7 @@ programs that read and write the same data: the terminal capture store, `.codige Windows (PowerShell), to `%LOCALAPPDATA%\Programs\codigest` and your user `PATH`: ```powershell -irm https://raw.githubusercontent.com/NaNIsaac/codigest/main/install.ps1 | iex +powershell -ExecutionPolicy Bypass -c "irm -useb https://raw.githubusercontent.com/NaNIsaac/codigest/main/install.ps1 | iex" ``` Linux, macOS and Termux, to `~/.local/bin` (`$PREFIX/bin` in Termux): diff --git a/site/index.md b/site/index.md index d432718..c04a6c5 100644 --- a/site/index.md +++ b/site/index.md @@ -20,7 +20,7 @@ install: windowsLabel: Windows unixLabel: Linux / macOS / Termux pythonLabel: Python (uv) - windows: 'irm https://raw.githubusercontent.com/NaNIsaac/codigest/main/install.ps1 | iex' + windows: 'powershell -ExecutionPolicy Bypass -c "irm -useb https://raw.githubusercontent.com/NaNIsaac/codigest/main/install.ps1 | iex"' unix: 'curl -fsSL https://raw.githubusercontent.com/NaNIsaac/codigest/main/install.sh | sh' python: 'uv tool install codigest' copy: Copy diff --git a/site/installation.md b/site/installation.md index eb1f561..0ecc050 100644 --- a/site/installation.md +++ b/site/installation.md @@ -2,10 +2,10 @@ ## Prebuilt binary (recommended) -One native binary, no Python needed. Windows (PowerShell): +One native binary, no Python needed. Windows (cmd or PowerShell): ```powershell -irm https://raw.githubusercontent.com/NaNIsaac/codigest/main/install.ps1 | iex +powershell -ExecutionPolicy Bypass -c "irm -useb https://raw.githubusercontent.com/NaNIsaac/codigest/main/install.ps1 | iex" ``` Linux, macOS and Termux: diff --git a/site/ko/index.md b/site/ko/index.md index f967d00..db04d95 100644 --- a/site/ko/index.md +++ b/site/ko/index.md @@ -20,7 +20,7 @@ install: windowsLabel: Windows unixLabel: Linux / macOS / Termux pythonLabel: Python (uv) - windows: 'irm https://raw.githubusercontent.com/NaNIsaac/codigest/main/install.ps1 | iex' + windows: 'powershell -ExecutionPolicy Bypass -c "irm -useb https://raw.githubusercontent.com/NaNIsaac/codigest/main/install.ps1 | iex"' unix: 'curl -fsSL https://raw.githubusercontent.com/NaNIsaac/codigest/main/install.sh | sh' python: 'uv tool install codigest' copy: 복사 diff --git a/site/ko/installation.md b/site/ko/installation.md index da2ebc9..18fa23b 100644 --- a/site/ko/installation.md +++ b/site/ko/installation.md @@ -2,10 +2,10 @@ ## 빌드된 바이너리 (권장) -네이티브 바이너리 하나이고 Python이 필요 없습니다. Windows (PowerShell): +네이티브 바이너리 하나이고 Python이 필요 없습니다. Windows (cmd 또는 PowerShell): ```powershell -irm https://raw.githubusercontent.com/NaNIsaac/codigest/main/install.ps1 | iex +powershell -ExecutionPolicy Bypass -c "irm -useb https://raw.githubusercontent.com/NaNIsaac/codigest/main/install.ps1 | iex" ``` Linux, macOS, Termux: diff --git a/site/ko/rust-port.md b/site/ko/rust-port.md index f987cf3..5ee5e38 100644 --- a/site/ko/rust-port.md +++ b/site/ko/rust-port.md @@ -13,7 +13,7 @@ Python 빌드의 모든 명령을 Rust로 옮겼고, 빌드된 바이너리가 C Windows(PowerShell)에서는 설치 스크립트가 `cdg.exe`를 `%LOCALAPPDATA%\Programs\codigest`에 넣고 그 폴더를 사용자 `PATH`에 추가합니다. ```powershell -irm https://raw.githubusercontent.com/NaNIsaac/codigest/main/install.ps1 | iex +powershell -ExecutionPolicy Bypass -c "irm -useb https://raw.githubusercontent.com/NaNIsaac/codigest/main/install.ps1 | iex" ``` Linux, macOS, Termux에서는 `cdg`를 `~/.local/bin`(Termux는 `$PREFIX/bin`)에 설치합니다. diff --git a/site/rust-port.md b/site/rust-port.md index 4a5963f..d1b3810 100644 --- a/site/rust-port.md +++ b/site/rust-port.md @@ -13,7 +13,7 @@ Both builds install a command called `cdg`, so keep one of them on `PATH`. They On Windows (PowerShell), the installer puts `cdg.exe` in `%LOCALAPPDATA%\Programs\codigest` and adds that folder to your user `PATH`: ```powershell -irm https://raw.githubusercontent.com/NaNIsaac/codigest/main/install.ps1 | iex +powershell -ExecutionPolicy Bypass -c "irm -useb https://raw.githubusercontent.com/NaNIsaac/codigest/main/install.ps1 | iex" ``` On Linux, macOS and Termux, it installs `cdg` to `~/.local/bin` (`$PREFIX/bin` in Termux):