1+ # GitX Windows Installer Script
2+ # Usage: Invoke-WebRequest -Uri "https://raw.githubusercontent.com/gitxtui/gitx/master/install.ps1" -OutFile "install.ps1"; .\install.ps1
3+
4+ $repo = " gitxtui/gitx"
5+ $installDir = " $env: ProgramFiles \gitx"
6+
7+ function Get-Arch {
8+ switch ($env: PROCESSOR_ARCHITECTURE ) {
9+ " AMD64" { return " amd64" }
10+ " ARM64" { return " arm64" }
11+ default { Write-Error " Unsupported architecture: $ ( $env: PROCESSOR_ARCHITECTURE ) " ; exit 1 }
12+ }
13+ }
14+
15+ function Get-LatestRelease {
16+ $apiUrl = " https://api.github.com/repos/$repo /releases"
17+ $response = Invoke-RestMethod - Uri $apiUrl
18+ if ($response -is [System.Collections.IEnumerable ] -and $response.Count -gt 0 ) {
19+ return $response [0 ].tag_name
20+ } else {
21+ Write-Error " Could not find any release version for $repo ."
22+ exit 1
23+ }
24+ }
25+
26+ function Main {
27+ $os = " windows"
28+ $arch = Get-Arch
29+ $version = Get-LatestRelease
30+ $versionNum = $version -replace " ^v" , " "
31+ $filename = " gitx_${versionNum} _${os} _${arch} .zip"
32+ $downloadUrl = " https://github.com/$repo /releases/download/$version /$filename "
33+
34+ Write-Host " Downloading gitx $version for $os /$arch ..."
35+ $tempDir = New-TemporaryFile | Split-Path
36+ $zipPath = Join-Path $tempDir $filename
37+ Invoke-WebRequest - Uri $downloadUrl - OutFile $zipPath
38+
39+ Write-Host " Extracting..."
40+ Expand-Archive - Path $zipPath - DestinationPath $tempDir
41+
42+ if (! (Test-Path $installDir )) {
43+ New-Item - ItemType Directory - Path $installDir | Out-Null
44+ }
45+
46+ $gitxExe = Get-ChildItem - Path $tempDir - Filter " gitx.exe" - Recurse | Select-Object - First 1
47+ if ($null -eq $gitxExe ) {
48+ Write-Error " gitx.exe not found in the archive."
49+ exit 1
50+ }
51+
52+ Copy-Item - Path $gitxExe.FullName - Destination (Join-Path $installDir " gitx.exe" ) - Force
53+
54+ Write-Host " `n gitx has been installed to $installDir "
55+ Write-Host " Add $installDir to your PATH if not already present."
56+ Write-Host " Run 'gitx.exe' to get started."
57+ }
58+
59+ Main
0 commit comments