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

exercism: install shell completions #369128

Merged

Conversation

kblcuk
Copy link
Contributor

@kblcuk kblcuk commented Dec 29, 2024

Exercism ships both with pre-generated completions [0], and has
completion command to generate completions for
bash/zsh/fish/powershell.
So this makes use of the latter and installShellCompletion.

[0] https://github.com/exercism/cli/tree/main/shell

@NixOSInfra NixOSInfra added the 12. first-time contribution This PR is the author's first one; please be gentle! label Dec 29, 2024
@kblcuk kblcuk marked this pull request as draft December 29, 2024 14:04
@kblcuk kblcuk force-pushed the exercism-install-shell-completions branch from f27efb7 to 90af30d Compare December 29, 2024 14:43
@kblcuk kblcuk marked this pull request as ready for review December 29, 2024 14:49
@kblcuk kblcuk force-pushed the exercism-install-shell-completions branch from 90af30d to 3836664 Compare December 29, 2024 17:44
Exercism ships both with pre-generated completions [0], and has
`completion` command to generate completions for
bash/zsh/fish/powershell.
Initially I was planning to use the latter, but seems like due to
a bug (?) in cobra-generated completions (probably [1]), the resulting
completions aren't fully working (if at all);
so this makes use of the ones provided in the repo. I'll probably update
this once more to use auto-generated completions once I manage to update
cobra dependency for exercism CLI itself.

[0] https://github.com/exercism/cli/tree/main/shell
[1] spf13/cobra#1940
@kblcuk kblcuk force-pushed the exercism-install-shell-completions branch from 3836664 to 01f52b4 Compare December 29, 2024 20:34
@FliegendeWurst FliegendeWurst merged commit 02fd7b2 into NixOS:master Dec 29, 2024
23 of 24 checks passed
@kblcuk kblcuk deleted the exercism-install-shell-completions branch December 30, 2024 06:56
kblcuk added a commit to kblcuk/cli that referenced this pull request Dec 31, 2024
...so generated completions are for the end result built, not the
current binary that we run. While the latter might make sense in some
cases (maybe?), I'd think the end goal with completions is to produce
them for the final result (so `exercism` command), not the intermediate
binary that we're building. Judging by Cobra's docs [0] that's the
intended usage here.
Also the current approach produces unusable completions for fish shell,
where function names can't have `/` in them. This can be observed by
making a test build and trying to source the completion result in fish
shell:

```fish
go build -o testercism ./exercism/main.go

./testercism completion fish | source
- (line 3): function: __./testercism_debug: invalid function name
...

This also makes autogenerated completions usable in nix, where
generation process would pass an absolute path to built binary when
calling completions script [1].

As this repo auto-suggests, I also created a forum thread regarding this
[2], but figured I might as well create a PR with possible solution.

[0] https://pkg.go.dev/github.com/spf13/cobra#Command
[1] NixOS/nixpkgs#369128
[2] https://forum.exercism.org/t/fish-shell-completion-generation-doesnt-always-work/14299
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants