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 Zsh completion #595

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

add Zsh completion #595

wants to merge 1 commit into from

Conversation

tastytea
Copy link

@tastytea tastytea commented Oct 2, 2022

This adds completion for Zsh. It should be installed into /usr/share/zsh/site-functions but i can't figure out how to do that with this build system. 😅

screenshots

reuse_zsh-completion
reuse_zsh-completion_licenses

@carmenbianca
Copy link
Member

This is great, but is there a way to auto-generate this? I'm not sure we have the know-how to maintain this.

Surely there's a somewhat standard way of doing autocomplete for argparse Python programs?

@tastytea
Copy link
Author

tastytea commented Oct 5, 2022

There is pycomplete (pycomplete 'reuse._main:parser()' zsh), but the result needs fixing and doesn't have license selection. It adds the long description to the short help text and doesn't add a help text to some subcommands for some reason.

screenshot

grafik

There is pyzshcomplete which works by integrating it into the source code. I could not get it to work, probably because i don't know python and was just guessing where to put the code.

@nicorikken
Copy link
Member

The pyzshcomplete readme describes how the Zsh completion is generated on the fly. We could already do it at 'buildtime' perhaps in Python using the argument structure? It is a nice feature for improved usability.

@linozen
Copy link
Contributor

linozen commented Nov 23, 2022

I added a meta issue to track completions for popular shells: #629

@sgaist
Copy link
Contributor

sgaist commented Nov 23, 2022

Hi,

One thing I have seen with several tools is that they have a "completion" subcommand that will output the completion file content for the selected shell on stdout. That way you do not require installation in a system specific (and possibly out of reach for the user) folder.

I think that would be a better alternative as it will allow users to make use of it with for example oh my zsh .

@DaveMcEwan
Copy link

Having a completion sub-command also makes it easier to maintain support for other shells. In a Rust project I work on, there's an argument --shell-completion which takes the name of any shell supported by clap_complete, i.e. Bash, Elvish, Fish, PowerShell, and Zsh. I think the installation process is too user-specific so just giving them a simple way to generate a completion script is a pragmatic compromise.
Mind you, the CLI of reuse-tool is so small and neat (thank you!) that this feature wouldn't really improve anybody's workflows in a significant way :p

@evelikov
Copy link
Contributor

This is great, but is there a way to auto-generate this? I'm not sure we have the know-how to maintain this.

Surely there's a somewhat standard way of doing autocomplete for argparse Python programs?

There are two ways in general. Dynamically (pycomplete, argcomplete) which work by invoking the program every time you press TAB or statically (python-shtab) which wraps argparse and generates normal completion files.

Since I'm a fan of the latter, opened a PR #1076

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.

7 participants