-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
85 lines (69 loc) · 3.77 KB
/
Copy pathinstall.ps1
File metadata and controls
85 lines (69 loc) · 3.77 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env pwsh
# install.ps1 — Install ttag on Windows
# Usage: irm https://raw.githubusercontent.com/dpkay-io/ttag/main/install.ps1 | iex
$ErrorActionPreference = "Stop"
$repo = "dpkay-io/ttag"
$installDir = Join-Path $HOME ".terminal_tagger\bin"
$binaryName = "ttag.exe"
Write-Host ""
Write-Host " ttag installer" -ForegroundColor Cyan
Write-Host " ─────────────────────────────" -ForegroundColor DarkGray
Write-Host ""
# ── Create install directory ──────────────────────────────────────────────────
if (-not (Test-Path $installDir)) {
New-Item -ItemType Directory -Path $installDir -Force | Out-Null
Write-Host " Created $installDir" -ForegroundColor DarkGray
}
# ── Detect architecture ──────────────────────────────────────────────────────
$arch = switch ($env:PROCESSOR_ARCHITECTURE) {
"ARM64" { "arm64" }
default { "amd64" }
}
Write-Host " Architecture: $arch" -ForegroundColor DarkGray
# ── Fetch latest release ─────────────────────────────────────────────────────
Write-Host " Fetching latest release..." -ForegroundColor DarkGray
$releaseUrl = "https://api.github.com/repos/$repo/releases/latest"
try {
$release = Invoke-RestMethod -Uri $releaseUrl -Headers @{
"User-Agent" = "ttag-installer"
"Accept" = "application/vnd.github+json"
}
} catch {
Write-Host " Error: Could not reach GitHub API." -ForegroundColor Red
Write-Host " $_" -ForegroundColor DarkRed
exit 1
}
$assetName = "ttag-windows-$arch.exe"
$asset = $release.assets | Where-Object { $_.name -eq $assetName }
if (-not $asset) {
Write-Host " Error: Asset '$assetName' not found in the latest release." -ForegroundColor Red
Write-Host " Available assets:" -ForegroundColor Yellow
$release.assets | ForEach-Object { Write-Host " - $($_.name)" }
exit 1
}
# ── Download binary ───────────────────────────────────────────────────────────
$downloadUrl = $asset.browser_download_url
$targetPath = Join-Path $installDir $binaryName
Write-Host " Downloading $assetName..." -ForegroundColor DarkGray
Invoke-WebRequest -Uri $downloadUrl -OutFile $targetPath -UseBasicParsing
if (-not (Test-Path $targetPath)) {
Write-Host " Error: Download failed." -ForegroundColor Red
exit 1
}
Write-Host " Saved to $targetPath" -ForegroundColor DarkGray
# ── Add to user PATH ─────────────────────────────────────────────────────────
$userPath = [Environment]::GetEnvironmentVariable("PATH", "User")
if ($userPath -notlike "*$installDir*") {
[Environment]::SetEnvironmentVariable("PATH", "$userPath;$installDir", "User")
$env:PATH = "$env:PATH;$installDir"
Write-Host " Added to PATH" -ForegroundColor DarkGray
} else {
Write-Host " Already in PATH" -ForegroundColor DarkGray
}
# ── Install shell hook ───────────────────────────────────────────────────────
Write-Host " Installing shell hook..." -ForegroundColor DarkGray
& $targetPath install --profile $PROFILE
Write-Host ""
Write-Host " ✓ ttag installed successfully!" -ForegroundColor Green
Write-Host " Restart your terminal to activate." -ForegroundColor Yellow
Write-Host ""