Created
March 31, 2025 08:56
-
-
Save alighafoori/57f5772bfa182651d417a97e6845f7cc to your computer and use it in GitHub Desktop.
Add 'Run with Bun' to Windows Right-Click Menu for .ts Files (PowerShell Script)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Ensure the script runs as administrator | |
$CurrentUser = [Security.Principal.WindowsIdentity]::GetCurrent() | |
$Principal = New-Object Security.Principal.WindowsPrincipal($CurrentUser) | |
$IsAdmin = $Principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) | |
if (-not $IsAdmin) { | |
Write-Host "Restarting with administrator privileges..." | |
Start-Process powershell -ArgumentList "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs | |
exit | |
} | |
$BunPath = "$env:USERPROFILE\.bun\bin\bun.exe" | |
$RegistryBase = "Registry::HKEY_CLASSES_ROOT\SystemFileAssociations\.ts\shell" | |
$RegistryPath = "$RegistryBase\Run with Bun" | |
$CommandPath = "$RegistryPath\command" | |
# Ensure the base key exists before creating subkeys | |
if (-not (Test-Path $RegistryBase)) { | |
New-Item -Path $RegistryBase -Force | Out-Null | |
} | |
# Create the registry keys | |
New-Item -Path $RegistryPath -Force | Out-Null | |
Set-ItemProperty -Path $RegistryPath -Name "(Default)" -Value "Run with Bun" | |
# Ensure the command key exists before setting the value | |
New-Item -Path $CommandPath -Force | Out-Null | |
# Properly format the command with extra double quotes | |
$CommandValue = "cmd /k `"`"$BunPath`" `"%1`"`"" | |
Set-ItemProperty -Path $CommandPath -Name "(Default)" -Value $CommandValue | |
Write-Host "Right-click menu for .ts files updated. Try right-clicking a .ts file!" | |
Read-Host "Press Enter to continue" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment