diff --git a/doc_src/cmds/complete.rst b/doc_src/cmds/complete.rst index b48722c93..f1b963d15 100644 --- a/doc_src/cmds/complete.rst +++ b/doc_src/cmds/complete.rst @@ -32,7 +32,7 @@ Description For an introduction to writing your own completions, see :ref:`Writing your own completions ` in the fish manual. -- ``-c COMMAND`` or ``--command COMMAND`` specifies that ``COMMAND`` is the name of the command. If there is no ``-c``, one non-option argument will be used as the command. +- ``-c COMMAND`` or ``--command COMMAND`` specifies that ``COMMAND`` is the name of the command. If there is no ``-c`` or ``-p``, one non-option argument will be used as the command. - ``-p COMMAND`` or ``--path COMMAND`` specifies that ``COMMAND`` is the absolute path of the command (optionally containing wildcards). diff --git a/src/complete.cpp b/src/complete.cpp index 929b9410c..928fbd462 100644 --- a/src/complete.cpp +++ b/src/complete.cpp @@ -1756,7 +1756,12 @@ static wcstring completion2string(const complete_entry_opt_t &o, const wcstring append_switch(out, L"requires-param"); } - append_switch(out, is_path ? L'p' : L'c', cmd); + if (is_path) + append_switch(out, L'p', cmd); + else { + out.append(L" "); + out.append(escape_string(cmd, ESCAPE_ALL)); + } switch (o.type) { case option_type_args_only: { @@ -1806,8 +1811,8 @@ wcstring complete_print(const wcstring &cmd) { const wcstring &src = entry.first; if (!cmd.empty() && src != cmd) continue; for (const wcstring &target : entry.second) { - out.append(L"complete"); - append_switch(out, L'c', src); + out.append(L"complete "); + out.append(escape_string(src, ESCAPE_ALL)); append_switch(out, L"wraps", target); out.append(L"\n"); } diff --git a/tests/checks/complete.fish b/tests/checks/complete.fish index 7f5583a34..4584d2a4f 100644 --- a/tests/checks/complete.fish +++ b/tests/checks/complete.fish @@ -50,14 +50,14 @@ complete -c 'complete test beta2' -r -d 'desc \' desc2 [' -a 'foo bar' complete -c complete_test_beta2 -x -n false -A -o test complete -# CHECK: complete --no-files -c complete_test_alpha1 -a '(commandline)' -# CHECK: complete --no-files -c complete_test_alpha2 -# CHECK: complete --no-files -c complete_test_alpha3 -# CHECK: complete --force-files -c t -l fileoption -# CHECK: complete --no-files -c t -a '(t)' +# CHECK: complete --no-files complete_test_alpha1 -a '(commandline)' +# CHECK: complete --no-files complete_test_alpha2 +# CHECK: complete --no-files complete_test_alpha3 +# CHECK: complete --force-files t -l fileoption +# CHECK: complete --no-files t -a '(t)' # CHECK: complete -p '/complete test/beta1' -s Z -d 'desc, desc' -# CHECK: complete --requires-param -c 'complete test beta2' -d desc\ \'\ desc2\ \[ -a 'foo bar' -# CHECK: complete --exclusive -c complete_test_beta2 -o test -n false +# CHECK: complete --requires-param 'complete test beta2' -d desc\ \'\ desc2\ \[ -a 'foo bar' +# CHECK: complete --exclusive complete_test_beta2 -o test -n false # CHECK: complete {{.*}} # CHECK: complete {{.*}} # CHECK: complete {{.*}} @@ -357,13 +357,13 @@ end # This should only list the completions for `banana` complete -c banana -a '1 2 3' complete -c banana -#CHECK: complete -c banana -a '1 2 3' +#CHECK: complete banana -a '1 2 3' # "-c" is optional complete banana -a bar complete banana -#CHECK: complete -c banana -a bar -#CHECK: complete -c banana -a '1 2 3' +#CHECK: complete banana -a bar +#CHECK: complete banana -a '1 2 3' # "-a" ain't complete banana bar @@ -374,3 +374,9 @@ complete banana bar #CHECKERR: ^ #CHECKERR: #CHECKERR: (Type 'help complete' for related documentation) + +# Multiple commands can be specified, in that case "-c" (or "-p") is mandatory. +complete -c kapstachelbeere -c physalis -a arg +complete -c kapstachelbeere -c physalis +# CHECK: complete kapstachelbeere -a arg +# CHECK: complete physalis -a arg