diff options
author | Thayne McCombs <astrothayne@gmail.com> | 2022-11-13 22:11:10 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-13 22:11:10 -0700 |
commit | ce4e8675ed12d96be74de8e8bd7f9ba28b61c0ab (patch) | |
tree | 59cd3e921ce8c76a4bbed068d7a460ec36f99ee3 | |
parent | 85e3adaf1800fd8cb192f7a4a2bb9000f993f5bc (diff) | |
parent | 2fcfe7a5b7f008c78c9507c520b5e86d97404a91 (diff) |
Merge pull request #1173 from zappolowski/fix-completion-program-name
Use just the file name of the program name for generating completions
-rw-r--r-- | src/main.rs | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs index 08a9881..1173b1e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -93,10 +93,16 @@ fn run() -> Result<ExitCode> { #[cold] fn print_completions(shell: clap_complete::Shell) -> Result<ExitCode> { // The program name is the first argument. - let program_name = env::args().next().unwrap_or_else(|| "fd".to_string()); + let first_arg = env::args().next(); + let program_name = first_arg + .as_ref() + .map(Path::new) + .and_then(|path| path.file_name()) + .and_then(|file| file.to_str()) + .unwrap_or("fd"); let mut cmd = Opts::command(); cmd.build(); - clap_complete::generate(shell, &mut cmd, &program_name, &mut std::io::stdout()); + clap_complete::generate(shell, &mut cmd, program_name, &mut std::io::stdout()); Ok(ExitCode::Success) } |