List time as builtin, support time --help

`a=b time foo` will no longer call an external `time` command
(like it does in bash).

Fixes #6598
This commit is contained in:
Johannes Altmanninger 2020-02-23 23:42:31 +01:00
parent 4fba8022a9
commit 7ef7f93a90
3 changed files with 6 additions and 15 deletions

View File

@ -394,6 +394,7 @@ static const builtin_data_t builtin_datas[] = {
{L"string", &builtin_string, N_(L"Manipulate strings")},
{L"switch", &builtin_generic, N_(L"Conditionally execute a block of commands")},
{L"test", &builtin_test, N_(L"Test a condition")},
{L"time", &builtin_generic, N_(L"Measure how long a command or block takes")},
{L"true", &builtin_true, N_(L"Return a successful result")},
{L"ulimit", &builtin_ulimit, N_(L"Set or get the shells resource usage limits")},
{L"wait", &builtin_wait, N_(L"Wait for background processes completed")},

View File

@ -397,16 +397,12 @@ RESOLVE(optional_background) {
}
RESOLVE(optional_time) {
UNUSED(token2);
switch (token1.keyword) {
case parse_keyword_time:
*out_tag = parse_optional_time_time;
return production_for<time>();
default:
*out_tag = parse_optional_time_no_time;
return production_for<empty>();
if (token1.keyword == parse_keyword_time && !token2.is_help_argument) {
*out_tag = parse_optional_time_time;
return production_for<time>();
}
*out_tag = parse_optional_time_no_time;
return production_for<empty>();
}
const production_element_t *parse_productions::production_for_token(parse_token_type_t node_type,

View File

@ -32,12 +32,6 @@ true && time a=b not builtin true | true
#CHECKERR: {{.*}}
#CHECKERR: {{.*}}
PATH= time true
#CHECKERR: fish: Unknown command: time
#CHECKERR: {{.*}}
#CHECKERR: PATH= time true
#CHECKERR: ^
not time true
#CHECKERR: ___{{.*}}
#CHECKERR: {{.*}}