optparse-applicative
optparse-applicative copied to clipboard
Add powershell autocompletion script generation
This almost completely addresses issue #315. I leverage the same mechanism as other completion scripts. There are some quirks however:
- on a windows machine, due to limitations of getProgName the script will work for
foo.exe, notfoo. I mention this in updated Readme. I will investigate the problem further, maybe it is safe to strip trailling.exe. - powershell-5 has some limitations - it does not trigger autocompletion on
foo --. This is a known issue, and it will not be fixed. Powershell-7 has no such limitations.
A review of my code and readme wording is most welcome!
Thanks for the contribution. I'll test this out soon.
I gave it a go on a unix system. Thanks again for putting in the time.
It looks like it's functioning ok, but I found a few quirks. I'm not on windows though, so your experience might be different.
Tab completions would always start with ./ if I don't write anything. So if there's a list of subcommands available, I need to type in a first letter for one of them? The default completer looks like it's overriding too much.
Options don't show their hyphens at the start. It looks like you've done this intentionally with a trim, but it strikes me as odd.
Option completion doesn't give a trailing space if the word is actually complete.
I can't seem to get it to show the tooltip. Again, maybe this is just the unix version.
I gave it a go on a unix system. Thanks again for putting in the time.
Thanks for testing my code!
It looks like it's functioning ok, but I found a few quirks. I'm not on windows though, so your experience might be different.
Tab completions would always start with
./if I don't write anything. So if there's a list of subcommands available, I need to type in a first letter for one of them? The default completer looks like it's overriding too much.
Do you mean that
$ foo [TAB]
results in $ foo ./? Or in $ foo ./nameOfAFileInThisFolder?
Options don't show their hyphens at the start. It looks like you've done this intentionally with a trim, but it strikes me as odd.
Indeed, I did it on purpose; though I do not have a really strong opinion on this, just a matter of taste. I can remove the trimming.
Option completion doesn't give a trailing space if the word is actually complete.
What's the scenario here?
$ foo --full-option[TAB]
should append a space, if I understand correctly?
I can't seem to get it to show the tooltip. Again, maybe this is just the unix version.
This most probably comes from the default settings of the PSReadLine module. This module is shipped by default for all pltaforms. Could you try putting
Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete in your session or in your $PROFILE? I honestly don't understand why this setting is not the default one. If tooltips come back, I'll amend the Readme. This setting might also fix some other problems that you encountered. In the meanwhile, I'll test subcommands in a linux env.
Indeed, I observe the same problem with subcommands, I'll look into it.
Regarding the space after trying to complete an already complete word, we can fix that by artificially appending a space to the completion result.
@HuwCampbell : Looks like @ShrykeWindgrace has pushed an update and waits for a re-review, or maybe I am misinterpreting the log here? (Just passing by...)
@andreasabel Indeed, thanks for bumping the thread, I myself forgot about this PR =)
For me, getting auto-completion for free was the killer argument to adopt optparse-applicative, so I think it is important that this feature is extended to a wider setting (meaning more shells, such as pwsh).
Yep, sorry I haven't been too on the spot for this one.
The completion scripts have a tendancy of being really subtle. I remember when I was improving the completion scripts for 0.14 I was refining and manually testing for days (it was for fish, zsh, and bash though).
I'll take another look.
@HuwCampbell Hi! It's been quite a while since the inception of this PR and since the last interaction in this thread. I understand perfectly well that during these stressful times carving a chunk of time to review this PR can be rather difficult.
So if it is indeed the case, could you give a rough estimation whether you'll have time for this in the foreseeable future? This PR is not a blocking feature for me, but I would welcome some new info.
Cheers!
Friendly ping =)
Hi.
I've just rebased this. The only issue major I can see at the moment is that when completing files, if you go to complete a directory it adds it withough the trailing slash. To get to a file within, you have to backspace, then add the slash, and then tab again from there instead of it adding it automatically.