mirror of
https://github.com/sharkdp/fd.git
synced 2024-11-16 08:58:26 +01:00
Merge pull request #1173 from zappolowski/fix-completion-program-name
Use just the file name of the program name for generating completions
This commit is contained in:
commit
ce4e8675ed
1 changed files with 8 additions and 2 deletions
10
src/main.rs
10
src/main.rs
|
@ -93,10 +93,16 @@ fn run() -> Result<ExitCode> {
|
||||||
#[cold]
|
#[cold]
|
||||||
fn print_completions(shell: clap_complete::Shell) -> Result<ExitCode> {
|
fn print_completions(shell: clap_complete::Shell) -> Result<ExitCode> {
|
||||||
// The program name is the first argument.
|
// 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();
|
let mut cmd = Opts::command();
|
||||||
cmd.build();
|
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)
|
Ok(ExitCode::Success)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue