Created
August 20, 2026 17:44
-
-
Save maphew/b424201cf003a8998ce8c7fafad434ad to your computer and use it in GitHub Desktop.
Draft Nushell Scoop Windows Terminal profile helper prototype for ScoopInstaller/Main#8421
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
| [CmdletBinding()] | |
| param( | |
| [switch] $Remove, | |
| [string] $FragmentRoot = [System.IO.Path]::Combine( | |
| $env:LOCALAPPDATA, | |
| 'Microsoft', | |
| 'Windows Terminal', | |
| 'Fragments', | |
| 'Nushell' | |
| ), | |
| [string] $NuPath | |
| ) | |
| $ErrorActionPreference = 'Stop' | |
| $fragmentPath = Join-Path $FragmentRoot 'nu.json' | |
| if ($Remove) { | |
| if (Test-Path -LiteralPath $fragmentPath) { | |
| Remove-Item -LiteralPath $fragmentPath -Force | |
| Write-Host "Removed the Windows Terminal profile fragment at '$fragmentPath'." | |
| } | |
| if ((Test-Path -LiteralPath $FragmentRoot) -and | |
| -not (Get-ChildItem -LiteralPath $FragmentRoot -Force)) { | |
| Remove-Item -LiteralPath $FragmentRoot -Force | |
| } | |
| return | |
| } | |
| if (-not $NuPath) { | |
| $prefix = (& scoop prefix nu | Select-Object -Last 1) | |
| if (-not $prefix) { | |
| throw "Could not determine Nushell's Scoop installation directory." | |
| } | |
| $NuPath = Join-Path $prefix 'nu.exe' | |
| } | |
| $NuPath = [System.IO.Path]::GetFullPath($NuPath) | |
| if (-not (Test-Path -LiteralPath $NuPath -PathType Leaf)) { | |
| throw "Nushell executable not found at '$NuPath'." | |
| } | |
| $profile = [ordered]@{ | |
| profiles = @( | |
| [ordered]@{ | |
| guid = '{d289a49c-671b-589c-b313-577976c1e147}' | |
| name = 'Nushell' | |
| commandline = '"{0}"' -f $NuPath | |
| icon = $NuPath | |
| hidden = $false | |
| } | |
| ) | |
| } | |
| New-Item -ItemType Directory -Path $FragmentRoot -Force | Out-Null | |
| $json = $profile | ConvertTo-Json -Depth 4 | |
| $tempPath = Join-Path $FragmentRoot 'nu.json.tmp' | |
| $utf8WithoutBom = New-Object System.Text.UTF8Encoding($false) | |
| try { | |
| [System.IO.File]::WriteAllText($tempPath, $json, $utf8WithoutBom) | |
| Move-Item -LiteralPath $tempPath -Destination $fragmentPath -Force | |
| } finally { | |
| Remove-Item -LiteralPath $tempPath -Force -ErrorAction SilentlyContinue | |
| } | |
| Write-Host "Added or updated the Windows Terminal profile fragment at '$fragmentPath'." |
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
| { | |
| "profiles": [ | |
| { | |
| "guid": "{d289a49c-671b-589c-b313-577976c1e147}", | |
| "name": "Nushell", | |
| "commandline": "%USERPROFILE%\\scoop\\shims\\nu.exe", | |
| "icon": "%USERPROFILE%\\scoop\\apps\\nu\\current\\nu.exe", | |
| "hidden": false | |
| } | |
| ] | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment