-
-
Notifications
You must be signed in to change notification settings - Fork 17
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
Shell completion script #133
Comments
I don't mind adding a separate dependency. Shell completion is a nice feature 👍🏻 I haven't used this crate though. How exactly does it work? Does it produce separate artifacts? On a similar note, |
The way I use it right now is that it just prints the script to stdout. I added the like
I think |
There are some follow up questions that need to be addressed before this is actually implemented all the way.
I personally rename the binary by hand so this will work for me as is, but for other users that might not be the case. A decision should be made on this naming convention before more work is done. I also did not find a way to create a custom list for suggestions for the install command, this could be solved by making a new enum that contains all the hardcoded tools. This would accrue a decent amount of maintenance load though since this enum, besides the actual hardcoded tools and config template, also has to be kept up to date. I found this issue that talks about a similar feature so I don't think this is currently possible. |
That's great to hear! 👏🏻 This is how it works in Haskell as well and how I enable completion on my own too 🙂
This is unfortunate 😞 |
For transparency's sake, it is possible to set a custom binary name for |
Since #136 is resolved thanks to @SanchithHegde, this issue can also be implemented. There is still the outstanding issue of how the naming convention should be for referring to We can also keep Other naming conventions are also welcome of course but these came to mind quickly. Changing the name later would also mean a breaking change. |
@MitchellBerend The conversation about naming conventions is spread across multiple places so I'm going to reply here. I've replied about the convention for the environment variables names in the corresponding issue: Could you clarify a bit more about the problem with the naming convention? I'm happy to call the binary |
Because the completion script needs to actually be ran every time a new shell without a parent is spawned my question was if we are using the name The way I'm reading your comment you want this to be |
@MitchellBerend Thanks for clarifying! I see the problem now 🙂 I would like to keep the name It would be better if It would be even better if users could configure the name for themselves so we don't need to support all possible use cases in our repo. But looks like the two last options are not possible, if I'm reading your comments correctly. |
I think we can support this by adding an optional flag possibly. There needs to be a special output to the stderr maybe since the command that gets run at first shell start up needs to hold only the completion script. Something like fn generate_custom_completion(bin_name: String, shell: clap_complete::Shell) {
let cmd = Cli::commands();
eprintln!(format!(r###"Add this to your ./bashrc:\n\teval "$({bin_name} completion --rename {bin_name})""###));
clap_complete::generate(shell, &mut cmd, bin_name, std::io::stdout());
} Edit: corrected |
This ended up being pretty easy to implement but there are still a few issues.
mitchell@mitchell-workstation:~/rust/tool-sync$ cargo run -- completion bash --rename asdfasdf -- $1 > /dev/null
Finished dev [unoptimized + debuginfo] target(s) in 0.04s
Running `target/debug/tool completion bash --rename asdfasdf --`
First, ensure that you install `bash-completion` using your package manager.
After, add this to your `~/.bash_profile`:
`eval "$(asdfasdf completion bash --rename asdfasdf)"`
----------------------------------------------------------------------------------------------------------------------------------------------------------------
mitchell@mitchell-workstation:~/rust/tool-sync$ cargo run -- completion fish --rename asdfasdf -- $1 > /dev/null
Finished dev [unoptimized + debuginfo] target(s) in 0.04s
Running `target/debug/tool completion fish --rename asdfasdf --`
Generate a `tool.fish` completion script:
`asdfasdf completion fish --rename asdfasdf > ~/.config/fish/completions/asdfasdf.fish`
----------------------------------------------------------------------------------------------------------------------------------------------------------------
mitchell@mitchell-workstation:~/rust/tool-sync$ cargo run -- completion zsh --rename asdfasdf -- $1 > /dev/null
Finished dev [unoptimized + debuginfo] target(s) in 0.04s
Running `target/debug/tool completion zsh --rename asdfasdf --`
Generate a `_asdfasdf` completion script and put it somewhere in your `$fpath`:
`asdfasdf completion zsh --rename asdfasdf > /usr/local/share/zsh/site-functions/_asdfasdf`
Ensure that the following is present in your `~/.zshrc`:
`autoload -U compinit`
`compinit -i`
----------------------------------------------------------------------------------------------------------------------------------------------------------------
mitchell@mitchell-workstation:~/rust/tool-sync$ cargo run -- completion powershell --rename asdfasdf -- $1 > /dev/null
Finished dev [unoptimized + debuginfo] target(s) in 0.04s
Running `target/debug/tool completion powershell --rename asdfasdf --`
Open your profile script with:
`mkdir -Path (Split-Path -Parent $profile) -ErrorAction SilentlyContinue`
`notepad $profile`
Add the line and save the file:
`Invoke-Expression -Command $(asdfasdf completion powershell --rename asdfasdf | Out-String)`
----------------------------------------------------------------------------------------------------------------------------------------------------------------
mitchell@mitchell-workstation:~/rust/tool-sync$ cargo run -- completion elvish --rename asdfasdf -- $1 > /dev/null
Finished dev [unoptimized + debuginfo] target(s) in 0.04s
Running `target/debug/tool completion elvish --rename asdfasdf --`
This suggestion is missing, if you use this and know how to implement this please file an issue over at https://github.com/chshersh/tool-sync/issues |
Resolves #133 This pr aims to add a tab completion script so users don't have to remember every command if they want to experiment with config options. ### Additional tasks - [x] Documentation for changes provided/changed - [x] Tests added - [x] Updated CHANGELOG.md Co-authored-by: Dmitrii Kovanikov <[email protected]>
The clap documentation points to clap_completion as a related project. Just like
tool-sync
can generate a default.tool.toml
I think it's a good idea for it to be able to generate shell completion scipts for commonly used shells (Bash, fish, zsh for example).clap_complete
supports these out of the box.It would add a new dependency to the project, but I think for what it provides that is more than worth it. I think implementing this should be straight forward, but the help text for this command should also contain instructions as to how this completion should be used.
Edit: blocked by #136Unblocked by @SanchithHegdeThe text was updated successfully, but these errors were encountered: