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

[WIP] Autogenerate shell completions #336

Closed
wants to merge 2 commits into from

Conversation

N-R-K
Copy link
Collaborator

@N-R-K N-R-K commented Jun 3, 2023

Recently someone mentioned compleat and this made me realize we already have (almost) all the necessary information to generate shell completion in our lopts array.

So that's what this does. This is very much an early draft/proof of concept - so I'd like some feedback on the overall structure/direction of this (don't pay too much attention to small details at the moment).

Shells like zsh supports having a short description which can be helpful to the user, so I've added a DESC macro. But it's optional, so I can drop it if it's too invasive.

To test out the zsh completion yourself, run the following (or equivalent) and then reload your shell:

$ tcc -run compautogen.c | doas tee /usr/local/share/zsh/site-functions/_scrot

Screenshot:

image


UPDATE: I think the generator is at a state where it is good enough.

However a couple other things need to be done before the PR can be merged:

  • Add a autoconf/make target (or script like the create-man.sh) to generate the output completion files
  • Make sure the generated completion files are picked up by make dist (I'm thinking we shouldn't commit the generated files into git)
  • Add the completions to install target as well

The last one might need more research since the "proper directory" to install completion files might vary distro to distro.

@N-R-K N-R-K marked this pull request as draft June 3, 2023 14:12
@N-R-K N-R-K linked an issue Jun 3, 2023 that may be closed by this pull request
3 tasks
compautogen.c Outdated Show resolved Hide resolved
@N-R-K
Copy link
Collaborator Author

N-R-K commented Aug 9, 2023

I was looking at mpv recently and the way they do auto-completion is by having a --list-options flag which outputs all the flags. The completion scripts then uses that output to configure itself.

I think this is probably a better approach than doing build time generation. It'll likely also attract more contributor since there are more people who can write shell scripts than people who can (or are willing to) write generators in C.

@N-R-K
Copy link
Collaborator Author

N-R-K commented May 27, 2024

Closing in favor of #377

@N-R-K N-R-K closed this May 27, 2024
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.

Support shell completion
1 participant