-
Notifications
You must be signed in to change notification settings - Fork 92
Add completions for bash and zsh #2853
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
Changes from all commits
b15e681
2a8dd22
194a8b0
d9b5adf
e62cbee
9e81312
d65694a
8b4a536
19233c5
4114a58
3e50974
b530baa
fd8b8a6
1a672cc
0dbda49
17fe587
f9d0e6b
4149067
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # .lychee.yaml | ||
| exclude: | ||
| - "https://www.gnu.org/software/libc/" | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| --- | ||
naomijub marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| title: Rover completion Commands | ||
| subtitle: Generate shell completion scripts for bash and zsh | ||
| description: Generate shell completion scripts to enable tab completion for Rover commands in bash and zsh shells. | ||
| --- | ||
|
|
||
| Rover provides shell completion support for bash and zsh, enabling tab completion for Rover commands and their options. This makes it easier to discover available commands and options while working in the terminal. | ||
|
|
||
| ## Generating completion scripts | ||
|
|
||
| ### `completion bash` | ||
|
|
||
| The `completion bash` command generates a bash completion script: | ||
|
|
||
| ``` | ||
| rover completion bash | ||
| ``` | ||
|
|
||
| This outputs a bash completion script to `stdout`. To enable bash completion, save the output to a file and source it in your shell configuration: | ||
|
|
||
| ```bash | ||
| # Save the completion script | ||
| rover completion bash > ~/.rover-completion.bash | ||
|
|
||
| # Add to your ~/.bashrc or ~/.bash_profile | ||
| echo "source ~/.rover-completion.bash" >> ~/.bashrc | ||
|
|
||
| # Reload your shell configuration | ||
| source ~/.bashrc # or restart your terminal | ||
| ``` | ||
|
|
||
| You'll now have tab completion for Rover commands. | ||
|
|
||
| ### `completion zsh` | ||
|
|
||
| The `completion zsh` command generates a zsh completion script: | ||
|
|
||
| ``` | ||
| rover completion zsh | ||
| ``` | ||
|
|
||
| This outputs a zsh completion script to `stdout`. To enable zsh completion, save the output to a file and source it in your shell configuration: | ||
|
|
||
| ```zsh | ||
| # Save the completion script | ||
| rover completion zsh > ~/.rover-completion.zsh | ||
|
|
||
| # Add to your ~/.zshrc | ||
| echo "source ~/.rover-completion.zsh" >> ~/.zshrc | ||
|
|
||
| # Reload your shell configuration | ||
| source ~/.zshrc # or restart your terminal | ||
| ``` | ||
|
|
||
| You'll now have tab completion for Rover commands. | ||
|
|
||
| Alternatively, you can use zsh's completion system by placing the script in your `fpath`: | ||
|
|
||
| ```zsh | ||
| # Create completion directory if it doesn't exist | ||
| mkdir -p /usr/local/share/zsh/site-functions | ||
|
|
||
| # Save the completion script to fpath | ||
| rover completion zsh > /usr/local/share/zsh/site-functions/_rover | ||
|
|
||
| # Reload completions (or restart your terminal) | ||
| compinit | ||
| ``` | ||
|
|
||
| ## Using completion | ||
|
|
||
| Once enabled, you can use tab completion to: | ||
|
|
||
| - Complete command names: Type `rover ` and press `Tab` to see available commands | ||
|
Check notice on line 74 in docs/source/commands/completion.mdx
|
||
| - Complete subcommands: Type `rover graph ` and press `Tab` to see available graph subcommands | ||
|
Check notice on line 75 in docs/source/commands/completion.mdx
|
||
| - Complete options: Type `rover graph publish ` and press `Tab` to see available options and flags | ||
|
Check notice on line 76 in docs/source/commands/completion.mdx
|
||
|
|
||
| ## Testing completion | ||
|
|
||
| To verify that completion is working correctly: | ||
|
|
||
| 1. Open a new terminal or reload your shell configuration | ||
| 2. Type `rover ` (with a space) and press `Tab` - you should see a list of available commands | ||
|
Check notice on line 83 in docs/source/commands/completion.mdx
|
||
| 3. Type `rover gra` and press `Tab` - it should autocomplete to `rover graph` | ||
|
Check notice on line 84 in docs/source/commands/completion.mdx
|
||
| 4. Continue typing `rover graph ` and press `Tab` - you should see available subcommands like `check`, `publish`, `fetch`, etc. | ||
|
Check notice on line 85 in docs/source/commands/completion.mdx
|
||
|
|
||
| If completion isn't working, ensure that: | ||
| - You've reloaded your shell configuration or opened a new terminal | ||
|
Check notice on line 88 in docs/source/commands/completion.mdx
|
||
| - The completion script file exists and is readable | ||
|
Check notice on line 89 in docs/source/commands/completion.mdx
|
||
| - For bash: The script is being sourced in your `~/.bashrc` or `~/.bash_profile` | ||
|
Check notice on line 90 in docs/source/commands/completion.mdx
|
||
| - For zsh: The script is being sourced in your `~/.zshrc` or is in your `fpath` | ||
|
Check notice on line 91 in docs/source/commands/completion.mdx
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| use clap::{CommandFactory, Parser}; | ||
| use clap_complete::{generate, shells::Bash as BashShell}; | ||
| use serde::Serialize; | ||
|
|
||
| use crate::{RoverOutput, RoverResult, cli::Rover}; | ||
|
|
||
| #[derive(Debug, Serialize, Parser)] | ||
| pub struct Bash {} | ||
|
|
||
| impl Bash { | ||
| pub fn run(&self) -> RoverResult<RoverOutput> { | ||
| let mut cmd = Rover::command(); | ||
| let name = "rover".to_string(); | ||
| generate(BashShell, &mut cmd, &name, &mut std::io::stdout()); | ||
| Ok(RoverOutput::EmptySuccess) | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| mod bash; | ||
| mod zsh; | ||
|
|
||
| use clap::Parser; | ||
| use serde::Serialize; | ||
|
|
||
| use crate::{RoverOutput, RoverResult}; | ||
|
|
||
| #[derive(Debug, Serialize, Parser)] | ||
| pub struct Completion { | ||
| #[clap(subcommand)] | ||
| command: Command, | ||
| } | ||
|
|
||
| #[derive(Debug, Serialize, Parser)] | ||
| enum Command { | ||
| /// Generate bash completion script | ||
| Bash(bash::Bash), | ||
|
|
||
| /// Generate zsh completion script | ||
| Zsh(zsh::Zsh), | ||
| } | ||
|
|
||
| impl Completion { | ||
| pub fn run(&self) -> RoverResult<RoverOutput> { | ||
| match &self.command { | ||
| Command::Bash(command) => command.run(), | ||
| Command::Zsh(command) => command.run(), | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| use clap::{CommandFactory, Parser}; | ||
| use clap_complete::{generate, shells::Zsh as ZshShell}; | ||
| use serde::Serialize; | ||
|
|
||
| use crate::{RoverOutput, RoverResult, cli::Rover}; | ||
|
|
||
| #[derive(Debug, Serialize, Parser)] | ||
| pub struct Zsh {} | ||
|
|
||
| impl Zsh { | ||
| pub fn run(&self) -> RoverResult<RoverOutput> { | ||
| let mut cmd = Rover::command(); | ||
| let name = "rover".to_string(); | ||
| generate(ZshShell, &mut cmd, &name, &mut std::io::stdout()); | ||
| Ok(RoverOutput::EmptySuccess) | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.