Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ members = [
async-trait = "0.1"
repos-github = { path = "common/repos-github" }
clap = { version = "4.4", features = ["derive"] }
clap_complete = "4.4"
serde = { version = "1.0", features = ["derive"] }
serde_yaml = "0.9"
serde_json = "1.0"
Expand Down
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,38 @@ cargo build --release
sudo cp target/release/repos /usr/local/bin/
```

### Shell Completions

`repos` can generate shell completions for zsh, bash, fish, PowerShell, and elvish.

#### Zsh

```bash
# Generate completions
repos completions zsh > ~/.zsh/completions/_repos

# Or for Oh My Zsh
mkdir -p ~/.oh-my-zsh/custom/plugins/repos-completions
repos completions zsh > ~/.oh-my-zsh/custom/plugins/repos-completions/_repos

# Add to your .zshrc
fpath=(~/.zsh/completions $fpath)
autoload -Uz compinit && compinit
```

#### Bash

```bash
repos completions bash > ~/.repos-completion.bash
echo 'source ~/.repos-completion.bash' >> ~/.bashrc
```

#### Fish

```bash
repos completions fish > ~/.config/fish/completions/repos.fish
```

## Quick Start

The easiest way to get started is to let `repos` generate a configuration file
Expand Down
21 changes: 19 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use anyhow::Result;
use clap::{Parser, Subcommand};
use clap::{CommandFactory, Parser, Subcommand};
use clap_complete::{Shell, generate};
use repos::commands::validators;
use repos::{commands::*, config::Config, constants, plugins};
use std::{env, path::PathBuf};
use std::{env, io, path::PathBuf};

#[derive(Parser)]
#[command(name = "repos")]
Expand Down Expand Up @@ -193,6 +194,13 @@ enum Commands {
supplement: bool,
},

/// Generate shell completions
Completions {
/// Shell to generate completions for
#[arg(value_enum)]
shell: Shell,
},

/// External plugin command
#[command(external_subcommand)]
External(Vec<String>),
Expand Down Expand Up @@ -221,6 +229,11 @@ async fn main() -> Result<()> {

// Handle commands
match cli.command {
Some(Commands::Completions { shell }) => {
let mut cmd = Cli::command();
generate(shell, &mut cmd, "repos", &mut io::stdout());
return Ok(());
}
Some(Commands::External(args)) => {
if args.is_empty() {
anyhow::bail!("External command provided but no arguments given");
Expand Down Expand Up @@ -502,6 +515,10 @@ async fn execute_builtin_command(command: Commands) -> Result<()> {
.execute(&context)
.await?;
}
Commands::Completions { .. } => {
// Handled in main(), this should not be reached
unreachable!("Completions command should be handled in main()")
}
}

Ok(())
Expand Down