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

Add powershell autocompletion script generation #420

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

ShrykeWindgrace
Copy link

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, not foo. 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!

@HuwCampbell
Copy link
Collaborator

Thanks for the contribution. I'll test this out soon.

@HuwCampbell
Copy link
Collaborator

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.

@ShrykeWindgrace
Copy link
Author

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.

@ShrykeWindgrace
Copy link
Author

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.

@andreasabel
Copy link
Contributor

@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...)

@ShrykeWindgrace
Copy link
Author

@andreasabel Indeed, thanks for bumping the thread, I myself forgot about this PR =)

@andreasabel
Copy link
Contributor

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).

@HuwCampbell
Copy link
Collaborator

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.

@ShrykeWindgrace
Copy link
Author

@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!

@ShrykeWindgrace
Copy link
Author

Friendly ping =)

ShrykeWindgrace added 3 commits May 30, 2023 14:19
- add note on `PSReadline` settings in order to get tooltips
- do not trim dashes in option names
- fix command index if we are completing an "empty word"
- add space if we are trying to complete a full word
@HuwCampbell
Copy link
Collaborator

HuwCampbell commented May 30, 2023

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.

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

Successfully merging this pull request may close these issues.

None yet

3 participants