Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Powershell autompletion script #315

Open
ShrykeWindgrace opened this issue Sep 6, 2018 · 5 comments
Open

Powershell autompletion script #315

ShrykeWindgrace opened this issue Sep 6, 2018 · 5 comments

Comments

@ShrykeWindgrace
Copy link

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
Copy link
Collaborator

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
Copy link
Collaborator

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
Copy link
Author

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
Copy link
Author

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
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants