diff --git a/doc_src/cmds/functions.rst b/doc_src/cmds/functions.rst index c5c193093..93ec0a417 100644 --- a/doc_src/cmds/functions.rst +++ b/doc_src/cmds/functions.rst @@ -39,6 +39,8 @@ The following options are available: You should not assume that only five lines will be written since we may add additional information to the output in the future. +- ``--no-details`` turns off function path reporting, so just the definition will be printed. + - ``-n`` or ``--names`` lists the names of all defined functions. - ``-q`` or ``--query`` tests if the specified functions exist. diff --git a/share/functions/funced.fish b/share/functions/funced.fish index 5d7df3271..583755ce3 100644 --- a/share/functions/funced.fish +++ b/share/functions/funced.fish @@ -60,7 +60,7 @@ function funced --description 'Edit function definition' if test "$editor" = fish if functions -q -- $funcname - functions -- $funcname | fish_indent --no-indent | read -z init + functions --no-details -- $funcname | fish_indent --no-indent | read -z init end set -l prompt 'printf "%s%s%s> " (set_color green) '$funcname' (set_color normal)' diff --git a/src/builtin_functions.cpp b/src/builtin_functions.cpp index 5b8bf8985..c6663424d 100644 --- a/src/builtin_functions.cpp +++ b/src/builtin_functions.cpp @@ -40,6 +40,7 @@ struct functions_cmd_opts_t { bool query = false; bool copy = false; bool report_metadata = false; + bool no_metadata = false; bool verbose = false; bool handlers = false; const wchar_t *handlers_type = nullptr; @@ -54,6 +55,7 @@ static const struct woption long_options[] = {{L"erase", no_argument, nullptr, ' {L"query", no_argument, nullptr, 'q'}, {L"copy", no_argument, nullptr, 'c'}, {L"details", no_argument, nullptr, 'D'}, + {L"no-details", no_argument, nullptr, 1}, {L"verbose", no_argument, nullptr, 'v'}, {L"handlers", no_argument, nullptr, 'H'}, {L"handlers-type", required_argument, nullptr, 't'}, @@ -78,6 +80,10 @@ static int parse_cmd_opts(functions_cmd_opts_t &opts, int *optind, //!OCLINT(hi opts.report_metadata = true; break; } + case 1: { + opts.no_metadata = true; + break; + } case 'd': { opts.description = w.woptarg; break; @@ -206,6 +212,12 @@ maybe_t builtin_functions(parser_t &parser, io_streams_t &streams, const wc return STATUS_INVALID_ARGS; } + if (opts.report_metadata && opts.no_metadata) { + streams.err.append_format(BUILTIN_ERR_COMBO, cmd); + builtin_print_error_trailer(parser, streams.err, cmd); + return STATUS_INVALID_ARGS; + } + if (opts.erase) { for (int i = optind; i < argc; i++) function_remove(argv[i]); return STATUS_CMD_OK; @@ -335,7 +347,9 @@ maybe_t builtin_functions(parser_t &parser, io_streams_t &streams, const wc if (!opts.query) { if (i != optind) streams.out.append(L"\n"); const wchar_t *funcname = argv[i]; - report_function_metadata(funcname, opts.verbose, streams, parser, true); + if (!opts.no_metadata) { + report_function_metadata(funcname, opts.verbose, streams, parser, true); + } wcstring def = functions_def(funcname); if (!streams.out_is_redirected && isatty(STDOUT_FILENO)) { diff --git a/tests/checks/functions.fish b/tests/checks/functions.fish index 1668a991f..2d7228afb 100644 --- a/tests/checks/functions.fish +++ b/tests/checks/functions.fish @@ -105,3 +105,15 @@ functions t # CHECK: echo tttt; # CHECK: end +functions --no-details t +# CHECK: function t +# CHECK: echo tttt; +# CHECK: end + +functions --no-details --details t +# CHECKERR: functions: Invalid combination of options +# CHECKERR: +# CHECKERR: checks/functions.fish (line {{\d+}}): +# CHECKERR: functions --no-details --details t +# CHECKERR: ^ +# CHECKERR: (Type 'help functions' for related documentation)