scrot icon indicating copy to clipboard operation
scrot copied to clipboard

[WIP] Autogenerate shell completions

Open N-R-K opened this issue 2 years ago • 1 comments

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 avatar Jun 03 '23 14:06 N-R-K

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 avatar Aug 09 '23 19:08 N-R-K

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

N-R-K avatar May 27 '24 04:05 N-R-K