pcapriotti / optparse-applicative

Applicative option parser
BSD 3-Clause "New" or "Revised" License
910 stars 116 forks source link

Powershell autompletion script #315

Open ShrykeWindgrace opened 6 years ago

ShrykeWindgrace commented 6 years ago

I use autocompletion scripts provided by optparse-applicative quite a lot in bash and zsh. Are there any plans to provide such scripts for powershell? Is is possible at all?

HuwCampbell commented 6 years ago

I'm glad to hear that you're enjoying the bash and zsh ones. I don't have a Windows installation right now, so can't really look into it for you at the moment. I'll revisit if that changes, but I'm also open to PRs.

HuwCampbell commented 5 years ago

Still don't have a windows machine. If you want to put up a PR though I can have a look. I think the biggest challenge is that we support bash functions for completions out of the box, and these will fail if bash isn't installed. User miles may vary in other words...

ShrykeWindgrace commented 5 years ago

Hi! To be honest, I am not really familiar with inner workings of powershell scripts, I guess I'll manage something partially working soon, but I do not promise anything definitive.

ShrykeWindgrace commented 4 years ago

A bit of necroposting: in fact, one does not need a windows machine to use powershell (per https://github.com/PowerShell/PowerShell, it's been cross-platform for quite some time).

A more useful remark for a user who has more time and desire to further this subject: it seems that Register-ArgumentCompleter with a carefully written ScriptBlock dynamically querying the desired executable with --bash-completion-index and --bash-completion-word behaves somewhat equivalent to current --bash-completion-script.

Again, I promise nothing, maybe in a year ( I know, right =)) I'll have a working solution.

ShrykeWindgrace commented 4 years ago

And a quick addendum:

$scriptblock = {
  param($commandName, $parameterName, $stringMatch)
    $result = & invoke-Expression "myExecutable.exe --bash-completion-index 0 --bash-completion-word $commandName"
    $result
    }
Register-ArgumentCompleter -Native -CommandName myExecutable.exe -ScriptBlock $scriptBlock

This script already gives a rudimentary tab-completion for names of long options - it only handles the cases --part-of-option, it does not work for -, --, nor for short options, neither it can validate the possible values of a parameter.