complete: fix completion of commands starting with -

When trying to complete a command starting with `-`, and more
specifically when trying to get the description of possible commands,
the dash was interpreted as an option for `__fish_describe_command`,
resulting in an "unknown option" most of the time.

This is a regression introduced when adding option parsing to
`__fish_describe_command`

Fixes 7fc27e9e5 (cygwin: improve handling of `.exe` file extension, 2025-11-22)
Fixes #12510

Closes #12522
This commit is contained in:
Nahor
2026-03-08 12:09:31 -07:00
committed by Johannes Altmanninger
parent e9340a3c43
commit c4aa03a1fd
2 changed files with 14 additions and 2 deletions

View File

@@ -999,11 +999,14 @@ fn complete_cmd_desc(&mut self, s: &wstr) {
// systems with a large set of manuals, but it should be ok since apropos is only called once.
// For Cygwin, also try to find the exact match for the non-exe name
let lookup_cmd = sprintf!(
"functions -q __fish_describe_command &&{ __fish_describe_command %s %s}",
"functions -q __fish_describe_command &&{ __fish_describe_command -- %s %s}",
&escape(cmd),
&no_exe
.map(|(cmd_sans_exe, _)| {
sprintf!("; __fish_describe_command --exact %s", escape(cmd_sans_exe))
sprintf!(
"; __fish_describe_command --exact -- %s",
escape(cmd_sans_exe)
)
})
.unwrap_or_default()[..]
);

View File

@@ -691,3 +691,12 @@ complete command-line-aware-completions -xa "(commandline --cursor; commandline
complete -C"command-line-aware-completions "
# CHECK: 31
# CHECK: command-line-aware-completions
begin
: >"$TMPDIR/-command-starting-with-dash"
chmod +x "$TMPDIR/-command-starting-with-dash"
set -l PATH "$TMPDIR" $PATH
complete -C"-command-starting-with"
# CHECK: -command-starting-with-dash{{\t}}command
end