Skip to content

Commit ce4e867

Browse files
authored
Merge pull request #1173 from zappolowski/fix-completion-program-name
Use just the file name of the program name for generating completions
2 parents 85e3ada + 2fcfe7a commit ce4e867

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/main.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,16 @@ fn run() -> Result<ExitCode> {
9393
#[cold]
9494
fn print_completions(shell: clap_complete::Shell) -> Result<ExitCode> {
9595
// The program name is the first argument.
96-
let program_name = env::args().next().unwrap_or_else(|| "fd".to_string());
96+
let first_arg = env::args().next();
97+
let program_name = first_arg
98+
.as_ref()
99+
.map(Path::new)
100+
.and_then(|path| path.file_name())
101+
.and_then(|file| file.to_str())
102+
.unwrap_or("fd");
97103
let mut cmd = Opts::command();
98104
cmd.build();
99-
clap_complete::generate(shell, &mut cmd, &program_name, &mut std::io::stdout());
105+
clap_complete::generate(shell, &mut cmd, program_name, &mut std::io::stdout());
100106
Ok(ExitCode::Success)
101107
}
102108

0 commit comments

Comments
 (0)