Skip to content

Adds shell completions for lychee#1972

Merged
mre merged 13 commits into
masterfrom
add-shell-completions
Mar 14, 2026
Merged

Adds shell completions for lychee#1972
mre merged 13 commits into
masterfrom
add-shell-completions

Conversation

@mre

@mre mre commented Dec 28, 2025

Copy link
Copy Markdown
Member

This follows ripgrep's lead and uses the same naming conventions for the CLI args. clap_complete does all the heavy-lifting, so there's no need to write our own generator. Completions get added to the binary releases.

@thomas-zahner, I tried to integrate the feature similar to your man page support (thanks for that!).

⚠️ TODO: Remove test-completions script before merging.

Also, we should probably update the homebrew recipe after the next release. Example from ripgrep: https://github.com/BurntSushi/ripgrep/blob/0a88cccd5188074de96f54a4b6b44a63971ac157/pkg/brew/ripgrep-bin.rb#L20

@mre mre requested a review from thomas-zahner December 28, 2025 15:30
@mre mre force-pushed the add-shell-completions branch from 39ff1d8 to e64b09c Compare December 28, 2025 16:07
Comment thread .github/workflows/test-completions.yml Outdated
Comment thread lychee-bin/src/commands/generate.rs
@mre mre force-pushed the add-shell-completions branch from 4a0217a to c765094 Compare December 28, 2025 16:20

@thomas-zahner thomas-zahner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much, cool addition 🚀
I haven't tested it yet. Before merging I would like to do so and update the nix-package accordingly

Comment thread lychee-bin/complete/README.md
Comment thread lychee-bin/complete/_lychee Outdated
@@ -0,0 +1,117 @@
#compdef lychee

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we shouldn't track any of these files (lychee-bin/complete/* expect readme), as they are generated either manually as described in the docs or via release workflow. Do you agree? We could then also consider moving lychee-bin/complete/README.md to docs/AUTOCOMPLETE.md

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ripgrep tracks them.. In my opinion, it's great to see the diff for future troubleshooting between versions of clap_complete.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh that surprises me..
Wouldn't we then also need a workflow, a test or some sort of automation to keep these generated files up to date? Otherwise, we constantly forget about keeping these files up-to-date.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically yes. That would be a nice addition, but it would also mean some additional work. These things tend to get tricky, especially with committing those files, which might trigger other workflows etc. But it's not strictly necessary in the beginning, in my opinion.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To expand on that a bit, I believe most people wouldn't care and for the few people who do, they get it out of the box as part of their release builds. We always bundle the latest versions. And the files in the repo are for troubleshooting, for the most part. I could add a make target to update them manually for now.

@thomas-zahner thomas-zahner Dec 29, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that's why personally I would not track those generated files at all. They should always be fully reproducible and as you say they are generated and included with every release. It would be less code, less files and we wouldn't have this problem of outdated files at all.

But if you really prefer to include them for debugging/troubleshooting we can do so.

Also if most people don't care, why should we care to add these files to the repository in the first place? 😅

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be interesting to know why ripgrep tracks them and if they have a mechanism to keep the files up-to-date.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did some research.

  1. They don't update the completions through CI, but they added a test to check that the completions are up-to-date, which is quite clever, because it would fail if contributors forget to update the file when new options get added: https://github.com/BurntSushi/ripgrep/blob/master/ci/test-complete

  2. One reason (perhaps the only one?) why they track the completion files is that the ZSH completions are handwritten. https://github.com/BurntSushi/ripgrep/blob/0a88cccd5188074de96f54a4b6b44a63971ac157/crates/core/flags/complete/zsh.rs#L4-L5

This way, they get a lot of confidence in their completions with little maintenance overhead. We could do the same.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the check

@thomas-zahner thomas-zahner Jan 1, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One reason (perhaps the only one?) why they track the completion files is that the ZSH completions are handwritten.

Ah that would make sense. Then one could argue that we don't need to track them, as we have no customisation or handwritten scripts. Also we could do the new CI shell completion tests by using the output of --generate and not track the generated files. I personally would prefer that. I think tracking the generated files only has any benefit, if we make manual adjustments to those files or if we intend to do so in the future.

Comment thread lychee-bin/src/commands/generate.rs
Comment thread .github/workflows/test-completions.yml Outdated
@mre

mre commented Dec 29, 2025

Copy link
Copy Markdown
Member Author

@thomas-zahner fyi, I tested it on bash, zsh and fish on macOS.

Todo before merging:

@mre mre force-pushed the add-shell-completions branch 3 times, most recently from ebd3f2b to d120d40 Compare December 29, 2025 16:55
@mre

mre commented Dec 29, 2025

Copy link
Copy Markdown
Member Author

The completion check makes the build slower (by ~30 seconds) because we have to build the binary first to run lychee --help. Maybe that's acceptable, but I'm open for suggestions. I would assume that it gets faster with subsequent runs because of the build cache.

@thomas-zahner

Copy link
Copy Markdown
Member

The completion check makes the build slower

Thanks for adding the test.

You do build specifically for the test script.

      - name: Build binary
        run: cargo build

I don't think this should be necessary.
See Test the "zsh shell completions (Unix, sans cross)" step which is part of the normal ci workflow, where the binary was built in a previous step already. This would probably save those 30 additional seconds?

@mre

mre commented Dec 31, 2025

Copy link
Copy Markdown
Member Author

Good idea. Let's try!

@thomas-zahner

thomas-zahner commented Jan 1, 2026

Copy link
Copy Markdown
Member

Cool. I've tested it with ZSH and it works perfectly fine. So it's fine to merge from my side. Only my comment about not tracking the generated files which I personally prefer. But I'm also fine with tracking them if you prefer it, or if you think we will soon do some manual adjustments to the scripts.

@mre

mre commented Jan 2, 2026

Copy link
Copy Markdown
Member Author

Yup! That did the trick. Checking completion takes all of 1 second now. Thanks for the tip!

@mre mre requested a review from thomas-zahner January 2, 2026 01:14

@katrinafyi katrinafyi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks really good and will be a great feature!

Personally, I also prefer not checking in the completions, as long as they're included in the release binaries (which it looks like they are :D)

Edit: Just tested with fish and it's really great. This will help usability a lot.


### Bash

**User installation:**

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just a sentence here that if a user has installed lychee through a package manager, then hopefully completions should work out of the box. Otherwise, they can try the manual steps and/or ping the package maintained.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, maybe add a gitignore in this folder for the generated files.

./lychee --generate complete-bash > complete/lychee.bash
./lychee --generate complete-elvish > complete/lychee.elv
./lychee --generate complete-fish > complete/lychee.fish
./lychee --generate complete-powershell > complete/_lychee.ps1

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block is repeated 3 times amongst the workflows. Can we use the makefile task instead? I'm just worried about subtle typos in the workflows that run less often, like release.

Comment thread scripts/check-completions.sh Outdated
@@ -0,0 +1,100 @@
#!/usr/bin/env bash

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The script is lovely and colourful, but is it needed if completions aren't checked in anymore? If make completions succeeds then it should all be up to date.

Comment thread .github/workflows/ci.yml Outdated
run: make test
# Shell completions are generated from CLI help and should be platform-independent
- name: Check completions are up to date
run: ./scripts/check-completions.sh

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this to fix CI?

mre added 10 commits March 14, 2026 00:06
This follows ripgrep's lead and uses the same naming conventions for the
CLI args. `clap_complete` does all of the heavy-lifting, so there's no
need to write our own generator. Completions get added to the binary
releases.
Adds PowerShell, GitHub, IPv4, and IPv6 to the list of valid
identifiers to prevent warnings about missing backticks in
documentation comments.

- Rustdoc configuration in Cargo.toml under [package.metadata.rustdoc]
- Clippy configuration in clippy.toml at workspace root
@mre mre force-pushed the add-shell-completions branch from 4a88fa9 to 04d44e7 Compare March 13, 2026 23:06
@mre

mre commented Mar 13, 2026

Copy link
Copy Markdown
Member Author

This is ready for another review. I think I addressed all comments now.

@mre mre merged commit 35a607d into master Mar 14, 2026
8 checks passed
@mre mre deleted the add-shell-completions branch March 14, 2026 10:00
@mre mre mentioned this pull request Mar 14, 2026
@mre mre mentioned this pull request Mar 25, 2026
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.

3 participants