Skip to content

Commit

Permalink
List time as builtin, support time --help
Browse files Browse the repository at this point in the history
`a=b time foo` will no longer call an external `time` command
(like it does in bash).

Fixes #6598
  • Loading branch information
krobelus committed Feb 23, 2020
1 parent 4fba802 commit 7ef7f93
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 15 deletions.
1 change: 1 addition & 0 deletions src/builtin.cpp
Expand Up @@ -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")},
Expand Down
14 changes: 5 additions & 9 deletions src/parse_productions.cpp
Expand Up @@ -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,
Expand Down
6 changes: 0 additions & 6 deletions tests/checks/time.fish
Expand Up @@ -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: {{.*}}
Expand Down

1 comment on commit 7ef7f93

@charlesbjohnson
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @krobelus!

Please sign in to comment.