rustimal 0.8.0

A minimal, GPU-rendered terminal for Windows that runs Git Bash, with animated split panes and a glass look
<#
.SYNOPSIS
  Install rustimal for the current user (no admin needed).

.DESCRIPTION
  - Copies the release build to %LOCALAPPDATA%\Programs\rustimal
  - Adds a Start menu shortcut (and optionally a desktop one)
  - Adds "Open in rustimal" to Explorer's right-click menu for folders, folder backgrounds and drives
  - Registers an App Path so Win+R -> "rustimal" works

  Re-run after rebuilding to update; it works even while rustimal is open.

  With -ExePath, nothing is built or copied: the shortcuts and menu entries point at
  that exe where it is (this is what `rustimal --install` uses after `cargo install`).

.EXAMPLE
  .\install.ps1            # build (if needed) and install
  .\install.ps1 -Desktop   # also add a desktop shortcut
  .\install.ps1 -Uninstall
#>
param(
    [switch]$Uninstall,
    [switch]$Desktop,
    [switch]$NoBuild,
    [string]$ExePath
)

$ErrorActionPreference = 'Stop'
$installDir = Join-Path $env:LOCALAPPDATA 'Programs\rustimal'
$exe = Join-Path $installDir 'rustimal.exe'
if ($ExePath) {
    $exe = (Resolve-Path -LiteralPath $ExePath).Path
    $installDir = Split-Path -Parent $exe
}
$startMenu = Join-Path $env:APPDATA 'Microsoft\Windows\Start Menu\Programs\rustimal.lnk'
$desktopLnk = Join-Path ([Environment]::GetFolderPath('Desktop')) 'rustimal.lnk'
$classes = 'HKCU:\Software\Classes'
$menuKeys = @(
    @{ Path = "$classes\Directory\Background\shell\rustimal"; Arg = '%V' },
    @{ Path = "$classes\Directory\shell\rustimal"; Arg = '%V' },
    @{ Path = "$classes\Drive\shell\rustimal"; Arg = '%V' }
)
$appPath = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\App Paths\rustimal.exe'

if ($Uninstall) {
    foreach ($k in $menuKeys) { Remove-Item -Path $k.Path -Recurse -Force -ErrorAction SilentlyContinue }
    Remove-Item -Path $appPath -Recurse -Force -ErrorAction SilentlyContinue
    Remove-Item -Path $startMenu, $desktopLnk -Force -ErrorAction SilentlyContinue
    # With -ExePath the exe lives somewhere we don't own (e.g. ~\.cargo\bin): leave it alone.
    if (-not $ExePath) { Remove-Item -Path $installDir -Recurse -Force -ErrorAction SilentlyContinue }
    Write-Host 'rustimal uninstalled. (Config in %APPDATA%\rustimal was kept.)'
    return
}

if (-not $ExePath) {
    $repo = $PSScriptRoot
    $built = Join-Path $repo 'target\release\rustimal.exe'
    if (-not $NoBuild) {
        Write-Host 'Building release...'
        Push-Location $repo
        try { cargo build --release; if ($LASTEXITCODE -ne 0) { throw 'cargo build failed' } } finally { Pop-Location }
    }
    if (-not (Test-Path $built)) { throw "No build found at $built" }

    # Copy the binary. A running exe can't be overwritten but can be renamed, so move it aside first.
    New-Item -ItemType Directory -Force -Path $installDir | Out-Null
    Get-ChildItem $installDir -Filter 'rustimal.old*.exe' -ErrorAction SilentlyContinue |
        ForEach-Object { Remove-Item $_.FullName -Force -ErrorAction SilentlyContinue }
    if (Test-Path $exe) {
        Rename-Item -Path $exe -NewName ("rustimal.old{0}.exe" -f (Get-Random)) -Force
    }
    Copy-Item -Path $built -Destination $exe -Force
}

# Shortcuts.
$shell = New-Object -ComObject WScript.Shell
$targets = @($startMenu)
if ($Desktop) { $targets += $desktopLnk }
foreach ($lnkPath in $targets) {
    $lnk = $shell.CreateShortcut($lnkPath)
    $lnk.TargetPath = $exe
    $lnk.WorkingDirectory = $env:USERPROFILE
    $lnk.IconLocation = "$exe,0"
    $lnk.Description = 'rustimal terminal'
    $lnk.Save()
}

# Explorer context menu.
foreach ($k in $menuKeys) {
    New-Item -Path $k.Path -Force | Out-Null
    Set-ItemProperty -Path $k.Path -Name '(default)' -Value 'Open in rustimal'
    Set-ItemProperty -Path $k.Path -Name 'Icon' -Value "`"$exe`",0"
    New-Item -Path "$($k.Path)\command" -Force | Out-Null
    Set-ItemProperty -Path "$($k.Path)\command" -Name '(default)' -Value "`"$exe`" `"$($k.Arg)`""
}

# Win+R / Start "rustimal".
New-Item -Path $appPath -Force | Out-Null
Set-ItemProperty -Path $appPath -Name '(default)' -Value $exe
Set-ItemProperty -Path $appPath -Name 'Path' -Value $installDir

Write-Host "rustimal installed to $exe"
Write-Host '  Start menu: rustimal   |   Win+R: rustimal   |   Explorer right-click: Open in rustimal'
Write-Host '  Tip: pin it to the taskbar from the Start menu entry.'