resurrecting-open-source-projects / scrot

SCReenshOT - command line screen capture utility
Other
495 stars 49 forks source link

[WIP] Autogenerate shell completions #336

Closed N-R-K closed 4 months ago

N-R-K commented 1 year ago

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:

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

N-R-K commented 1 year ago

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 commented 4 months ago

Closing in favor of https://github.com/resurrecting-open-source-projects/scrot/pull/377