Skip to content

Commit

Permalink
Add shell completion subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
ede1998 committed Nov 1, 2024
1 parent 555cde0 commit 3452946
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 23 deletions.
134 changes: 112 additions & 22 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions fclones/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ bytesize = "1.1"
byte-unit = "4.0"
chrono = { version = "0.4", default-features = false, features = ["serde", "clock", "std"] }
clap = { version = "4.4", features = ["derive", "cargo", "wrap_help"] }
clap_complete = { version = "4.5.36" }
console = "0.15"
crossbeam-channel = "0.5"
crossbeam-utils = "0.8"
Expand Down
14 changes: 14 additions & 0 deletions fclones/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,20 @@ are also attached directly to [Releases](https://github.com/pkolaczk/fclones/rel

The build will write the binary to `.cargo/bin/fclones`.

### Shell completions

`fclones` supports shell completions but you have to set it up manually at the moment,
which can be done by adding the script printed by the `fclones complete` subcommand to your shell configuration.
All shells supported by [clap_complete](https://docs.rs/clap_complete/latest/clap_complete/aot/enum.Shell.html) are supported.
At the time of writing this includes:

- Bash: Add `eval "$(fclones complete bash)"` to your `~/.bashrc`
- Zsh: Add `source <(fclones complete zsh)` to your `~/.zshrc`
- Fish: Add `fclones complete fish | source` to your `~/.config/fish/config.fish`
- Elvish
- Powershell


## Usage

`fclones` offers separate commands for finding and removing files. This way, you can inspect
Expand Down
12 changes: 12 additions & 0 deletions fclones/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,12 @@ pub enum Command {
#[arg()]
target: PathBuf,
},

/// Print shell completion script to stdout.
Complete {
/// Shell for which the completion script is generated.
shell: clap_complete::Shell,
},
}

impl Command {
Expand Down Expand Up @@ -801,4 +807,10 @@ mod test {
config.command,
Command::Move { target, .. } if target == PathBuf::from("target"));
}

#[test]
fn test_complete_command() {
let config: Config = Config::try_parse_from(vec!["fclones", "complete", "zsh"]).unwrap();
assert_matches!(config.command, Command::Complete { shell } if shell == clap_complete::Shell::Zsh);
}
}
Loading

0 comments on commit 3452946

Please sign in to comment.