-
Notifications
You must be signed in to change notification settings - Fork 3
feat: add the ability to generate shell completions #11
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
Conversation
Can't we do this somehow dynamically? |
Do you mean at build time? The advantage of the approach I've used is that it's easy to generate completions regardless of how the tool is installed. Most other Rust CLI tools seem to use a similar strategy based on my own experience. Feel free to let me know what you have in mind. Cheers |
I thought about initializing them on first usage or something like that |
Ah gotcha. Tomorrow when I'm back on my PC, I'll respond in more detail with examples of what other popular projects do so we can figure out next steps. The vast majority now offer a way to generate completions for your chosen shell using the tool itself. Some generate them at build time and package them, which I personally don't prefer as they don't agree with tools like cargo binstall. More to follow tomorrow 😊 Cheers |
Okies, so here's a view of how some popular Rust tools handle completion generation. At Build Timehyperfine uses bottom uses dust uses At Runtimecargo (nightly) generates completions when the And here are the commands for generating PowerShell completions at runtime for various other popular Rust CLI tools: bat --completion ps1
dprint completions powershell
fd --gen-completions powershell
procs --gen-completion-out powershell
rg --generate complete-powershell
rustup completions powershell
starship completions power-shell
# Implemented by me and merged by the project authors. 😄
dua completions powershell
xh --generate complete-powershell I think it's worth talking about pros and cons of both approaches. Pros at Runtime:
Pros at Build Time:
Personally, I feel that generating completions at runtime is the vastly superior choice and is fool-proof and more reliable. Kindly let me know your thoughts 😄 |
yeah you are right at runtime is I think the best option |
I must admit that I'm still not quite sure how you see that working. Do you mean that upon first running the tool, it'll detect your shell and automatically place completions in the relevant directory for you? If so, this is definitely a big no-no for the following reasons:
Based on my own experience with both Rust projects and those in other languages, completions are made available only using the methods described above. Either they are embedded into the binary and can be displayed to stdout (most common) or written to a chosen path (much less common), or they are provided during build time or distribution of the application as files. Kindly let me know how you wish to proceed 😄 Cheers |
I was thinking about the same problems but was unsure if there is still a correct solution |
Thank you so much! 😊 |
Hey again,
This PR adds the ability to generate shell completions for common shells. If you also are interested in Nushell completions, an additional crate and some extra code is required. Please let me know. 😄
I've ensured the tests pass this time too, sorry about last time.
Cheers
Fotis