Skip to content

Completion of FilePath adds space in zsh #6178

@windsource

Description

@windsource

Please complete the following tasks

Rust Version

rustc 1.91.0 (f8297e351 2025-10-28)

Clap Version

clap 4.5.51, clap_complete 4.5.60

Minimal reproducible code

use std::path::PathBuf;

use clap::{CommandFactory, Parser, ValueHint};
use clap_complete::CompleteEnv;

#[derive(Parser, Debug, PartialEq)]
#[command(name = "mycomp")]
struct Opt {
    #[arg(value_hint = ValueHint::FilePath)]
    file: PathBuf,
}

fn main() {
    CompleteEnv::with_factory(|| Opt::command()).complete();
    let opt = Opt::parse();

    println!("{:#?}", opt.file);
}

Steps to reproduce the bug with the above code

If the binary is called mycomp, then in zsh (not bash!):

source <(COMPLETE=zsh mycomp)

Then assume your current folder looks like

. -
  +- sub1
     +- sub2

Then using completion like

mycomp <TAB>

Actual Behaviour

You get

mycomp sub1/<SPACE>

so pressing tab again will not show sub2. In bash the behavior is correct (not adding space here).

Expected Behaviour

If there are still files or sub folders available for completion, no space should be added (same as in bash).

Additional Context

Based on discussion in #6176

Debug Output

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-completionArea: completion generatorC-bugCategory: bugE-help-wantedCall for participation: Help is requested to fix this issue.E-mediumCall for participation: Experience needed to fix: Medium / intermediate

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions