From 7d5c64a731e1c6e2adf33723301f2dc855e63019 Mon Sep 17 00:00:00 2001 From: Collin Styles Date: Tue, 27 Apr 2021 16:14:58 -0700 Subject: [PATCH] Fix completions to cargo's `--example` option on macOS The completions for the `--example` option are generated using `find`. The `find` utility on macOS will produce the following output when the path argument has a trailing slash: ``` ~/bat $ find ./examples/ ./examples/ ./examples//cat.rs ./examples//advanced.rs ./examples//simple.rs ./examples//list_syntaxes_and_themes.rs ./examples//yaml.rs ``` And will produce this output if the path does NOT have a trailing slash: ``` ~/bat $ find ./examples ./examples ./examples/cat.rs ./examples/advanced.rs ./examples/simple.rs ./examples/list_syntaxes_and_themes.rs ./examples/yaml.rs ``` The extra slash after `examples` ends up in the completion suggestions which is incorrect: ``` ~/bat $ cargo run --example /advanced /cat /list_syntaxes_and_themes /simple /yaml ``` Unlike on my Linux box where `find` doesn't output the trailing slash: ``` ~/bat $ cargo run --example advanced cat inputs list_syntaxes_and_themes simple yaml ``` Importantly, I get the same (correct) output on Linux even without the trailing slash in the path argument to `find`. --- share/completions/cargo.fish | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/share/completions/cargo.fish b/share/completions/cargo.fish index 1f7bbc4a1..ded85ed35 100644 --- a/share/completions/cargo.fish +++ b/share/completions/cargo.fish @@ -17,7 +17,7 @@ function __list_cargo_examples return end - find ./examples/ -mindepth 1 -maxdepth 1 -type f -name "*.rs" -or -type d \ + find ./examples -mindepth 1 -maxdepth 1 -type f -name "*.rs" -or -type d \ | string replace -r './examples/(.*?)(?:.rs)?$' '$1' end for x in bench b build r run rustc t test