|
| 1 | +#!/usr/bin/env pwsh |
| 2 | +# install.ps1 — Install ttab on Windows |
| 3 | +# Usage: irm https://raw.githubusercontent.com/dpkay-io/ttab/main/install.ps1 | iex |
| 4 | + |
| 5 | +$ErrorActionPreference = "Stop" |
| 6 | + |
| 7 | +$repo = "dpkay-io/ttab" |
| 8 | +$installDir = Join-Path $HOME ".terminal_tagger" "bin" |
| 9 | +$binaryName = "ttab.exe" |
| 10 | + |
| 11 | +Write-Host "" |
| 12 | +Write-Host " ttab installer" -ForegroundColor Cyan |
| 13 | +Write-Host " ─────────────────────────────" -ForegroundColor DarkGray |
| 14 | +Write-Host "" |
| 15 | + |
| 16 | +# ── Create install directory ────────────────────────────────────────────────── |
| 17 | +if (-not (Test-Path $installDir)) { |
| 18 | + New-Item -ItemType Directory -Path $installDir -Force | Out-Null |
| 19 | + Write-Host " Created $installDir" -ForegroundColor DarkGray |
| 20 | +} |
| 21 | + |
| 22 | +# ── Detect architecture ────────────────────────────────────────────────────── |
| 23 | +$arch = switch ($env:PROCESSOR_ARCHITECTURE) { |
| 24 | + "ARM64" { "arm64" } |
| 25 | + default { "amd64" } |
| 26 | +} |
| 27 | +Write-Host " Architecture: $arch" -ForegroundColor DarkGray |
| 28 | + |
| 29 | +# ── Fetch latest release ───────────────────────────────────────────────────── |
| 30 | +Write-Host " Fetching latest release..." -ForegroundColor DarkGray |
| 31 | +$releaseUrl = "https://api.github.com/repos/$repo/releases/latest" |
| 32 | + |
| 33 | +try { |
| 34 | + $release = Invoke-RestMethod -Uri $releaseUrl -Headers @{ |
| 35 | + "User-Agent" = "ttab-installer" |
| 36 | + "Accept" = "application/vnd.github+json" |
| 37 | + } |
| 38 | +} catch { |
| 39 | + Write-Host " Error: Could not reach GitHub API." -ForegroundColor Red |
| 40 | + Write-Host " $_" -ForegroundColor DarkRed |
| 41 | + exit 1 |
| 42 | +} |
| 43 | + |
| 44 | +$assetName = "ttab-windows-$arch.exe" |
| 45 | +$asset = $release.assets | Where-Object { $_.name -eq $assetName } |
| 46 | + |
| 47 | +if (-not $asset) { |
| 48 | + Write-Host " Error: Asset '$assetName' not found in the latest release." -ForegroundColor Red |
| 49 | + Write-Host " Available assets:" -ForegroundColor Yellow |
| 50 | + $release.assets | ForEach-Object { Write-Host " - $($_.name)" } |
| 51 | + exit 1 |
| 52 | +} |
| 53 | + |
| 54 | +# ── Download binary ─────────────────────────────────────────────────────────── |
| 55 | +$downloadUrl = $asset.browser_download_url |
| 56 | +$targetPath = Join-Path $installDir $binaryName |
| 57 | + |
| 58 | +Write-Host " Downloading $assetName..." -ForegroundColor DarkGray |
| 59 | +Invoke-WebRequest -Uri $downloadUrl -OutFile $targetPath -UseBasicParsing |
| 60 | + |
| 61 | +if (-not (Test-Path $targetPath)) { |
| 62 | + Write-Host " Error: Download failed." -ForegroundColor Red |
| 63 | + exit 1 |
| 64 | +} |
| 65 | + |
| 66 | +Write-Host " Saved to $targetPath" -ForegroundColor DarkGray |
| 67 | + |
| 68 | +# ── Add to user PATH ───────────────────────────────────────────────────────── |
| 69 | +$userPath = [Environment]::GetEnvironmentVariable("PATH", "User") |
| 70 | +if ($userPath -notlike "*$installDir*") { |
| 71 | + [Environment]::SetEnvironmentVariable("PATH", "$userPath;$installDir", "User") |
| 72 | + $env:PATH = "$env:PATH;$installDir" |
| 73 | + Write-Host " Added to PATH" -ForegroundColor DarkGray |
| 74 | +} else { |
| 75 | + Write-Host " Already in PATH" -ForegroundColor DarkGray |
| 76 | +} |
| 77 | + |
| 78 | +# ── Install shell hook ─────────────────────────────────────────────────────── |
| 79 | +Write-Host " Installing shell hook..." -ForegroundColor DarkGray |
| 80 | +& $targetPath install --profile $PROFILE |
| 81 | + |
| 82 | +Write-Host "" |
| 83 | +Write-Host " ✓ ttab installed successfully!" -ForegroundColor Green |
| 84 | +Write-Host " Restart your terminal to activate." -ForegroundColor Yellow |
| 85 | +Write-Host "" |
0 commit comments