-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
65 lines (56 loc) · 2.72 KB
/
Copy pathinstall.ps1
File metadata and controls
65 lines (56 loc) · 2.72 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
# binvim Windows installer.
#
# iwr https://binvim.dev/install.ps1 -UseBasicParsing | iex
#
# Optional environment overrides:
# $env:BINVIM_VERSION = 'v0.5.19' # pin to a specific tag (default: latest)
# $env:BINVIM_INSTALL_DIR = 'C:\bin' # override install dir
# (default: $env:LOCALAPPDATA\binvim\bin)
$ErrorActionPreference = 'Stop'
$repo = 'bgunnarsson/binvim'
$installDir = if ($env:BINVIM_INSTALL_DIR) { $env:BINVIM_INSTALL_DIR } else {
Join-Path $env:LOCALAPPDATA 'binvim\bin'
}
function Info($msg) { Write-Host "==> $msg" -ForegroundColor Cyan }
function Fail($msg) { Write-Error $msg; exit 1 }
# Resolve the release tag — pinned via $env:BINVIM_VERSION or the
# latest GitHub release.
$version = $env:BINVIM_VERSION
if (-not $version) {
Info 'resolving latest release'
$api = Invoke-RestMethod "https://api.github.com/repos/$repo/releases/latest" -UseBasicParsing
$version = $api.tag_name
if (-not $version) { Fail 'could not resolve latest release; set $env:BINVIM_VERSION explicitly' }
}
# Only x86_64-pc-windows-msvc ships today; ARM64 Windows will need its own
# matrix entry in release.yml when that becomes a real target.
$target = 'x86_64-pc-windows-msvc'
$archive = "binvim-$version-$target.zip"
$url = "https://github.com/$repo/releases/download/$version/$archive"
$tmp = Join-Path $env:TEMP "binvim-install-$([guid]::NewGuid())"
New-Item -ItemType Directory -Path $tmp | Out-Null
try {
Info "downloading $archive"
Invoke-WebRequest -Uri $url -OutFile (Join-Path $tmp $archive) -UseBasicParsing
Info 'extracting'
Expand-Archive -Path (Join-Path $tmp $archive) -DestinationPath $tmp -Force
New-Item -ItemType Directory -Path $installDir -Force | Out-Null
Move-Item -Force (Join-Path $tmp 'binvim.exe') (Join-Path $installDir 'binvim.exe')
if (Test-Path (Join-Path $tmp 'binvim-install.exe')) {
Move-Item -Force (Join-Path $tmp 'binvim-install.exe') (Join-Path $installDir 'binvim-install.exe')
}
Info "installed binvim $version → $installDir\binvim.exe"
} finally {
Remove-Item -Recurse -Force $tmp -ErrorAction SilentlyContinue
}
# PATH hint — we don't mutate the registry on the user's behalf;
# print the one-liner instead so it's reversible.
$path = [Environment]::GetEnvironmentVariable('Path', 'User')
if (-not ($path -split ';' | Where-Object { $_ -eq $installDir })) {
Write-Host ''
Write-Host "note: $installDir is not on your user PATH."
Write-Host ' add it for this session:'
Write-Host " `$env:Path = `"$installDir;`$env:Path`""
Write-Host ' add it permanently:'
Write-Host " [Environment]::SetEnvironmentVariable('Path', `"$installDir;`" + [Environment]::GetEnvironmentVariable('Path','User'), 'User')"
}