Skip to content

Instantly share code, notes, and snippets.

@MovGP0
Last active August 11, 2025 09:58
Show Gist options
  • Select an option

  • Save MovGP0/1cfb47045379fb3da3e9e418b6898fac to your computer and use it in GitHub Desktop.

Select an option

Save MovGP0/1cfb47045379fb3da3e9e418b6898fac to your computer and use it in GitHub Desktop.
NuShell PowerShell CLI completions

Setup

  1. Place the file into $AppData\Roaming\nushell\completions\pwsh-completions.nu
  2. add the following line at the end of $AppData\Roaming\nushell\config.nu
source ~/AppData/Roaming/nushell/completions/pwsh-completions.nu
  1. add the following line to ~/AppData/Roaming/nushell/env.nu to execute PowerShell scripts directly:
# to execute powershell scripts
export def ps1 [script:path] {
  pwsh -WorkingDirectory $env.PWD -File $script
}
export def "nu-complete pwsh executionpolicy" [] {
# Canonical ExecutionPolicy values
[AllSigned Bypass Default RemoteSigned Restricted Unrestricted]
}
export def "nu-complete pwsh windowstyle" [] {
[Normal Minimized Maximized Hidden]
}
# Return `null` to fall back to Nu's file/path completion (per docs)
export def "nu-complete pwsh path" [] { null }
# Optional: discover available PSSession configurations (if any)
export def "nu-complete pwsh configurationname" [] {
try {
^pwsh -NoProfile -Command "Get-PSSessionConfiguration | Select-Object -ExpandProperty Name" | lines
} catch { [] }
}
# ---- extern signature for pwsh ---------------------------------------------
export extern "pwsh" [
# info
--help(-h) # show help
--version(-v) # show version
# startup behavior
--login # login shell (Unix)
--nologo
--noprofile
--noninteractive
--sta # Windows
--mta # Windows
# session config / files
--configurationname: string@"nu-complete pwsh configurationname"
--configurationfile: string@"nu-complete pwsh path"
--settingsfile: string@"nu-complete pwsh path"
--custompipename: string
# execution
--executionpolicy(-e): string@"nu-complete pwsh executionpolicy"
--workingdirectory(-d): string@"nu-complete pwsh path"
--windowstyle(-w): string@"nu-complete pwsh windowstyle"
--file(-f): string@"nu-complete pwsh path" # .ps1 file (or - to read stdin)
--command(-c): string # script block or string
--commandwithargs: string # Windows-only convenience
--encodedcommand: string # base64-encoded script
--args(-a): list<string> # args when using -Command
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment