Skip to content

unstable-dynamic completion for fish shell invalid when binary path has a space #6196

@devjgm

Description

@devjgm

Please complete the following tasks

Rust Version

rustc 1.91.0 (f8297e351 2025-10-28)

Clap Version

4.5.53

Minimal reproducible code

use clap::CommandFactory;

#[derive(clap::Parser, Debug)]
struct Args;

fn main() {
    clap_complete::env::CompleteEnv::with_factory(|| Args::command()).complete();
    // Nothing
}
[package]
name = "clap-complete-bug"
version = "0.1.0"
edition = "2024"

[dependencies]
clap = { version = "4.5.53", features = ["derive"] }
clap_complete = { version = "4.5.61", features = ["unstable-dynamic"] }

Steps to reproduce the bug with the above code

  • Build a project with the code above. cargo build
  • Run the binary with COMPLETE=fish ./target/debug/clap-complete-bug. So far, THIS IS OK
COMPLETE=fish ./target/debug/clap-complete-bug
complete --keep-order --exclusive --command clap-complete-bug --arguments "(COMPLETE=fish "'/Users/greg/clap-complete-bug/./target/debug/clap-complete-bug'" -- (commandline --current-process --tokenize --cut-at-cursor) (commandline --current-token))"

The bug

  • Use a symlink to add a space in the path to the binary
ln -s ./target/debug/clap-complete-bug "with space"
  • Now run the binary with COMPLETE=fish using the path with a space
COMPLETE=fish ./with\ space 
complete --keep-order --exclusive --command clap-complete-bug --arguments "(COMPLETE=fish "''/Users/greg/clap-complete-bug/./with space''" -- (commandline --current-process --tokenize --cut-at-cursor) (commandline --current-token))"
  • Notice how the generated path has too many quotes around the path. Fish is unable to run the command:
complete --keep-order --exclusive --command clap-complete-bug --arguments "(COMPLETE=fish "''/Users/greg/clap-complete-bug/./with space''" -- (commandline --current-process --tokenize --cut-at-cursor) (commandline -
-current-token))"
complete: too many arguments

(Type 'help complete' for related documentation)

Actual Behaviour

COMPLETE=fish /path with a space/my-binary produces invalid fish syntax due to invalid quoting around the path with a space.

Expected Behaviour

I expect the produced paths to be quoted correctly with or without spaces.

Additional Context

This will be a somewhat common issue because on macOS, paths like Library/Application Support have spaces, and binaries in those directories will not be able to use dynamic clap completions.

Note: If you're open to it, I'd be willing to send a PR.

Debug Output

❯ COMPLETE=fish ./with\ space
[clap_builder::builder::command]Command::_build: name="clap-complete-bug"
[clap_builder::builder::command]Command::_propagate:clap-complete-bug
[clap_builder::builder::command]Command::_check_help_and_version:clap-complete-bug expand_help_tree=true
[clap_builder::builder::command]Command::long_help_exists
[clap_builder::builder::command]Command::_check_help_and_version: Building default --help
[clap_builder::builder::command]Command::_propagate_global_args:clap-complete-bug
[clap_builder::builder::debug_asserts]Command::_debug_asserts
[clap_builder::builder::debug_asserts]Arg::_debug_asserts:help
[clap_builder::builder::debug_asserts]Command::_verify_positionals
[clap_builder::builder::command]Command::_build_bin_names
[ clap_builder::output::usage]Usage::get_required_usage_from: incls=[], matcher=false, incl_last=true
[ clap_builder::output::usage]Usage::get_required_usage_from: unrolled_reqs=[]
[ clap_builder::output::usage]Usage::get_required_usage_from: ret_val=[]
complete --keep-order --exclusive --command clap-complete-bug --arguments "(COMPLETE=fish "''/Users/greg/clap-complete-bug/./with space''" -- (commandline --current-process --tokenize --cut-at-cursor) (commandline --current-token))"

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-completionArea: completion generatorC-bugCategory: bugE-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