mirror of
https://github.com/sharkdp/fd.git
synced 2024-11-16 08:58:26 +01:00
ef1bfc7508
Replace the auto-generated Zsh completion with a full completion script. This script improves completion support for options and arguments, which is hard to obtain from an auto-generated completion. - Full completion support for external commands and options when using `--exec`/`--exec-batch`. - The completion for `--type` and `--color` adds descriptions instead of just values. - Complete files when using `--ignore-file`. - Stop completing files for the pattern argument. - Improve completion for path arguments. Only directories are completed. - Single-use options are not offered again. - Updated exclusions lists for mutual-exclusive options. - Add support for hidden options (as defined in `app.rs`). They are not offered for completion, but if present are considered (and their value may be completed). Full support for exclusion lists depends of options groups, which was added in Zsh 5.4. Older Zsh versions, as commented in the completion script, will just offer most options. The format of the completion script was taken from ripgrep completion script. Command completion for `--exec`/`--exec-batch` was taken from Zsh's `_find` completion.
30 lines
792 B
Rust
30 lines
792 B
Rust
use std::fs;
|
|
|
|
use clap::Shell;
|
|
|
|
include!("src/app.rs");
|
|
|
|
fn main() {
|
|
let min_version = "1.36";
|
|
|
|
match version_check::is_min_version(min_version) {
|
|
Some(true) => {}
|
|
// rustc version too small or can't figure it out
|
|
_ => {
|
|
eprintln!("'fd' requires rustc >= {}", min_version);
|
|
std::process::exit(1);
|
|
}
|
|
}
|
|
|
|
let var = std::env::var_os("SHELL_COMPLETIONS_DIR").or(std::env::var_os("OUT_DIR"));
|
|
let outdir = match var {
|
|
None => return,
|
|
Some(outdir) => outdir,
|
|
};
|
|
fs::create_dir_all(&outdir).unwrap();
|
|
|
|
let mut app = build_app();
|
|
app.gen_completions("fd", Shell::Bash, &outdir);
|
|
app.gen_completions("fd", Shell::Fish, &outdir);
|
|
app.gen_completions("fd", Shell::PowerShell, &outdir);
|
|
}
|