-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
202 lines (170 loc) · 5.63 KB
/
Copy pathinstall.ps1
File metadata and controls
202 lines (170 loc) · 5.63 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#Requires -Version 5.1
<#
.SYNOPSIS
Magic Shell Installer for Windows
.DESCRIPTION
Downloads and installs Magic Shell on Windows systems.
.PARAMETER Version
Specific version to install. Defaults to 'latest'.
.PARAMETER InstallDir
Installation directory. Defaults to $env:LOCALAPPDATA\magic-shell\bin
.EXAMPLE
irm https://raw.githubusercontent.com/austin-thesing/magic-shell/main/install.ps1 | iex
.EXAMPLE
.\install.ps1 -Version v0.1.0
#>
param(
[string]$Version = "latest",
[string]$InstallDir = "$env:LOCALAPPDATA\magic-shell\bin"
)
$ErrorActionPreference = "Stop"
# Configuration
$Repo = "austin-thesing/magic-shell"
$PackageName = "magic-shell"
function Write-Info {
param([string]$Message)
Write-Host "info " -ForegroundColor Blue -NoNewline
Write-Host $Message
}
function Write-Success {
param([string]$Message)
Write-Host "success " -ForegroundColor Green -NoNewline
Write-Host $Message
}
function Write-Warn {
param([string]$Message)
Write-Host "warn " -ForegroundColor Yellow -NoNewline
Write-Host $Message
}
function Write-Error-Custom {
param([string]$Message)
Write-Host "error " -ForegroundColor Red -NoNewline
Write-Host $Message
exit 1
}
function Get-Architecture {
$arch = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture
switch ($arch) {
"X64" { return "x64" }
"Arm64" { return "arm64" }
default { Write-Error-Custom "Unsupported architecture: $arch" }
}
}
function Get-LatestVersion {
Write-Info "Fetching latest version..."
try {
$release = Invoke-RestMethod -Uri "https://api.github.com/repos/$Repo/releases/latest"
return $release.tag_name
}
catch {
Write-Error-Custom "Failed to fetch latest version: $_"
}
}
function Install-ViaNpm {
Write-Info "Installing via npm..."
# Check for package managers in order of preference
if (Get-Command bun -ErrorAction SilentlyContinue) {
Write-Info "Using bun..."
bun add -g @austinthesing/magic-shell
}
elseif (Get-Command npm -ErrorAction SilentlyContinue) {
Write-Info "Using npm..."
npm install -g @austinthesing/magic-shell
}
elseif (Get-Command yarn -ErrorAction SilentlyContinue) {
Write-Info "Using yarn..."
yarn global add @austinthesing/magic-shell
}
elseif (Get-Command pnpm -ErrorAction SilentlyContinue) {
Write-Info "Using pnpm..."
pnpm add -g @austinthesing/magic-shell
}
else {
Write-Error-Custom "No package manager found. Please install Node.js/npm, Bun, Yarn, or pnpm first."
}
Write-Success "Installed @austinthesing/magic-shell via npm"
return $true
}
function Install-Binary {
$arch = Get-Architecture
$platform = "windows-$arch"
if ($Version -eq "latest") {
$Version = Get-LatestVersion
}
Write-Info "Version: $Version"
Write-Info "Platform: $platform"
# Create temp directory
$tempDir = New-Item -ItemType Directory -Path "$env:TEMP\magic-shell-install-$(Get-Random)"
try {
# Download URL (adjust based on your release asset naming)
$downloadUrl = "https://github.com/$Repo/releases/download/$Version/magic-shell-$Version-$platform.zip"
$zipPath = Join-Path $tempDir "magic-shell.zip"
Write-Info "Downloading from $downloadUrl..."
try {
Invoke-WebRequest -Uri $downloadUrl -OutFile $zipPath -UseBasicParsing
}
catch {
Write-Warn "Binary release not found, falling back to npm install..."
Install-ViaNpm
return
}
Write-Info "Extracting..."
Expand-Archive -Path $zipPath -DestinationPath $tempDir -Force
Write-Info "Installing to $InstallDir..."
if (-not (Test-Path $InstallDir)) {
New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null
}
# Copy executable
Copy-Item -Path (Join-Path $tempDir "magic-shell.exe") -Destination $InstallDir -Force
# Create batch file shortcuts for msh and ms
$mshBat = @"
@echo off
"%~dp0magic-shell.exe" %*
"@
Set-Content -Path (Join-Path $InstallDir "msh.cmd") -Value $mshBat
Set-Content -Path (Join-Path $InstallDir "ms.cmd") -Value $mshBat
Write-Success "Installed magic-shell $Version to $InstallDir"
# Add to PATH
Add-ToPath
}
finally {
# Cleanup
Remove-Item -Path $tempDir -Recurse -Force -ErrorAction SilentlyContinue
}
}
function Add-ToPath {
$currentPath = [Environment]::GetEnvironmentVariable("Path", "User")
if ($currentPath -split ";" | Where-Object { $_ -eq $InstallDir }) {
Write-Info "Already in PATH"
return
}
Write-Info "Adding to PATH..."
$newPath = "$currentPath;$InstallDir"
[Environment]::SetEnvironmentVariable("Path", $newPath, "User")
# Also update current session
$env:Path = "$env:Path;$InstallDir"
Write-Success "Added to PATH"
}
function Show-PostInstall {
Write-Host ""
Write-Success "Installation complete!"
Write-Host ""
Write-Host "To get started:"
Write-Host " 1. Open a new terminal (to refresh PATH)"
Write-Host ""
Write-Host " 2. Set up your API key:"
Write-Host " msh --setup"
Write-Host ""
Write-Host " 3. Try it out:"
Write-Host " msh `"list all files`""
Write-Host ""
}
# Main
function Main {
Write-Host ""
Write-Host "Magic Shell Installer" -ForegroundColor Blue
Write-Host ""
Install-Binary
Show-PostInstall
}
Main