fish : how to get completions for powershell scripts


When running powershell, powershell scripts automatically provide parameter tab completion, such as we love to experience in fish, based on the Param block:

Param(
  (int)$param1,
  (ValidateSet('nc6','nc12','nc24'))(string)$param2,
  (ValidateScript({Test-Path $_ -PathType 'Leaf'}))(string)$param3
)

How could I do completion for fish that would work either (a) for a specific powershell script or much better (b) for any powershell script?

The best I can see at the moment is to write code to automate the steps:

  • search for *.ps1 files
  • inspect each file, extract the Param() block
  • generate completion statements e.g. for the above I think I’d want to generate exactly four lines
complete -c myscript.ps1 -f
complete -c myscript.ps1 -o param1
complete -c myscript.ps1 -o param2 -a "nc6 nc12 nc24"
complete -c myscript.ps1 -F -o param3

Is there some better route that I’m missing that would allow fish to instead ask pwsh “tell me the completions”, or has someone already done anything on this?