Skip to content

Commit

Permalink
Merge pull request #1173 from zappolowski/fix-completion-program-name
Browse files Browse the repository at this point in the history
Use just the file name of the program name for generating completions
  • Loading branch information
tmccombs authored Nov 14, 2022
2 parents 85e3ada + 2fcfe7a commit ce4e867
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit ce4e867

Please sign in to comment.