diff --git a/CHANGELOG.rst b/CHANGELOG.rst index b0237de3c..f593e1a9e 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -36,6 +36,7 @@ Interactive improvements - Case-changing autosuggestions generated mid-token now correctly append only the suffix, instead of duplicating the token (:issue:`8820`). - ``ulimit`` learned a number of new options for the resource limits available on Linux, FreeBSD and NetBSD, and returns a specific warning if the limit specified is not available on the active operating system (:issue:`8823`). - The ``vared`` command can now successfully edit variables named "tmp" or "prompt" (:issue:`8836`). +- ``time`` now emits an error if used after the first command in a pipeline (:issue:`8841`). New or improved bindings ^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/parse_util.cpp b/src/parse_util.cpp index c74c20b8d..b42d4d2d3 100644 --- a/src/parse_util.cpp +++ b/src/parse_util.cpp @@ -39,6 +39,9 @@ /// Error message for arguments to 'end' #define END_ARG_ERR_MSG _(L"'end' does not take arguments. Did you forget a ';'?") +/// Error message when 'time' is in a pipeline. +#define TIME_IN_PIPELINE_ERR_MSG _(L"The 'time' command may only be at the beginning of a pipeline") + /// Maximum length of a variable name to show in error reports before truncation static constexpr int var_err_len = 16; @@ -1123,6 +1126,11 @@ static bool detect_errors_in_decorated_statement(const wcstring &buff_src, errored = append_syntax_error(parse_errors, source_start, INVALID_PIPELINE_CMD_ERR_MSG, command.c_str()); } + + // Similarly for time (#8841). + if (command == L"time") { + errored = append_syntax_error(parse_errors, source_start, TIME_IN_PIPELINE_ERR_MSG); + } } // $status specifically is invalid as a command, diff --git a/tests/checks/syntax-error-location.fish b/tests/checks/syntax-error-location.fish index ca483f45c..3f2aebfdc 100644 --- a/tests/checks/syntax-error-location.fish +++ b/tests/checks/syntax-error-location.fish @@ -11,6 +11,12 @@ $status # CHECK: # CHECK: < ^> +echo 'true | time false' | $fish 2>| string replace -r '(.*)' '<$1>' +# CHECK: +# CHECK: +# CHECK: < ^> + + echo ' (true one)