diff --git a/src/parse_util.cpp b/src/parse_util.cpp index dc09d3071..ea55eca5f 100644 --- a/src/parse_util.cpp +++ b/src/parse_util.cpp @@ -1165,8 +1165,16 @@ static bool detect_errors_in_decorated_statement(const wcstring &buff_src, // Similarly for time (#8841). if (command == L"time") { - errored = append_syntax_error(parse_errors, source_start, source_length, - TIME_IN_PIPELINE_ERR_MSG); + // We only reject it if we have no decoration. + // `echo foo | command time something` + // is entirely fair and valid. + // Other current decorations like "exec" + // are already forbidden. + const auto &deco = dst.decoration(); + if (deco == statement_decoration_t::none) { + errored = append_syntax_error(parse_errors, source_start, source_length, + TIME_IN_PIPELINE_ERR_MSG); + } } } diff --git a/tests/checks/time.fish b/tests/checks/time.fish index d42130739..f4fe070e1 100644 --- a/tests/checks/time.fish +++ b/tests/checks/time.fish @@ -48,3 +48,17 @@ $fish -c 'not time true&' #CHECKERR: not time true& #FIXME: This error marks the entire statement. Would be cool to mark just `time true&`. #CHECKERR: ^~~~~~~~~~~~~^ + +$fish -c 'echo Is it time yet | time cat' +#CHECKERR: fish: The 'time' command may only be at the beginning of a pipeline +#CHECKERR: echo Is it time yet | time cat +#CHECKERR: ^~~~~~~^ + +begin + printf '%s\n' "#!/bin/sh" 'echo No this is Patrick' > time + chmod +x time + set -l PATH . + echo Hello is this time | command time + # CHECK: No this is Patrick +end +rm time