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

autocompletions #117

Open
cgsdev0 opened this issue Apr 3, 2024 · 6 comments
Open

autocompletions #117

cgsdev0 opened this issue Apr 3, 2024 · 6 comments
Assignees
Labels
enhancement New feature or request

Comments

@cgsdev0
Copy link
Contributor

cgsdev0 commented Apr 3, 2024

if you assign this to me ill do it

@amonks
Copy link
Owner

amonks commented Apr 4, 2024

@cgsdev0 assigned 💞

@amonks amonks added the enhancement New feature or request label Apr 5, 2024
@amonks
Copy link
Owner

amonks commented Apr 5, 2024

@cgsdev0 How does shipping shell completions work?

Is it like a man page where you have to put a file in some os-dependent place on disk?

(I'm really asking: how does this ticket impact our install process? would we need to integrate with package managers?)

@cgsdev0
Copy link
Contributor Author

cgsdev0 commented Apr 5, 2024

i don't really know tbh

we can try to find some prior art

@amonks
Copy link
Owner

amonks commented Apr 5, 2024

got curious, did some digging.

shells expect to find a "completion file", which is a shell script that invokes that shell's "complete" builtin a lot of times, in a particular os-specific shell-specific folder.


one prior art

the cobra library (very fancy go framework for cli tools) adds a command to your CLI which prints a completion file for a given shell:

$tool completion --shell {bash|fish|zsh|powershell}

A user can then run something like this to install the completion:

$tool completion --shell fish > "(pkg-config --variable completionsdir fish)/$tool.fish"

Their pacakge-manager configurations work the same way, eg Macports


another prior art is https://github.com/posener/complete/tree/master, which seems a teensy bit ramshackle (the api is poorly considered, it installs completions to the wrong place, the installed completion prints a stacktrace when I hit tab to execute it) but it does have some cute nuggets:

  • it offers an API for installing a completion file (rather than just printing it)
  • that generated completion file ends up being a wrapper around your cli tool's own binary, so your shell ends up invoking your binary with special flags when you hit tab and offering completion options based on whatever it prints

that second bit is particularly interesting: it suggests that we can, eg, parse a local taskfile with our regular go taskfile parsing to generate completions on-the-fly

@cgsdev0
Copy link
Contributor Author

cgsdev0 commented Apr 5, 2024

that second bit is particularly interesting: it suggests that we can, eg, parse a local taskfile with our regular go taskfile parsing to generate completions on-the-fly

yeah this is the main feature i had in mind

i will probably start with just writing the completions file, and then we can worry about how to get it installed 👍

@amonks
Copy link
Owner

amonks commented Apr 5, 2024

sounds cool; lookin' forward to it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants