diff --git a/doc_src/cmds/complete.rst b/doc_src/cmds/complete.rst index 1821bd57f..c817b36e7 100644 --- a/doc_src/cmds/complete.rst +++ b/doc_src/cmds/complete.rst @@ -8,7 +8,7 @@ Synopsis :: - complete ( -c | --command | -p | --path ) COMMAND + complete [( -c | --command | -p | --path )] COMMAND [( -c | --command | -p | --path ) COMMAND]... [( -e | --erase )] [( -s | --short-option ) SHORT_OPTION]... diff --git a/src/builtin_complete.cpp b/src/builtin_complete.cpp index f4455b7da..934277477 100644 --- a/src/builtin_complete.cpp +++ b/src/builtin_complete.cpp @@ -299,6 +299,9 @@ maybe_t builtin_complete(parser_t &parser, io_streams_t &streams, wchar_t * if (do_complete && !have_do_complete_param && argc == w.woptind + 1) { do_complete_param = argv[argc - 1]; have_do_complete_param = true; + } else if (!do_complete && cmd_to_complete.empty() && argc == w.woptind + 1) { + // Or use one left-over arg as the command to complete + cmd_to_complete.push_back(argv[argc - 1]); } else { streams.err.append_format(BUILTIN_ERR_TOO_MANY_ARGUMENTS, cmd); builtin_print_error_trailer(parser, streams.err, cmd); diff --git a/tests/checks/complete.fish b/tests/checks/complete.fish index bee026421..e463490ed 100644 --- a/tests/checks/complete.fish +++ b/tests/checks/complete.fish @@ -358,3 +358,19 @@ end complete -c banana -a '1 2 3' complete -c banana #CHECK: complete -c 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' + +# "-a" ain't +complete banana bar +#CHECKERR: complete: Too many arguments +#CHECKERR: +#CHECKERR: {{.*}}checks/complete.fish (line {{\d+}}): +#CHECKERR: complete banana bar +#CHECKERR: ^ +#CHECKERR: +#CHECKERR: (Type 'help complete' for related documentation)