Point to builtins begin/end when a failed command starts with "{"

Closes #6415
This commit is contained in:
Johannes Altmanninger 2021-06-23 21:45:32 +02:00
parent 565a7e4bc5
commit 48c1550f61
4 changed files with 15 additions and 0 deletions

View File

@ -55,6 +55,7 @@ Interactive improvements
- The Web-based configuration and documentation now feature a dark mode if the browser requests it (:issue:`8043`).
- Color variables can now also be given like ``--background red`` and ``-b red``, not just ``--background=red`` (:issue:`8053`).
- ``exit`` run within ``fish_prompt`` now exits properly (:issue:`8033`).
- When attempting to execute the unsupported POSIX-style brace command group (``{ ... }``) fish will suggest its equivalent ``begin; ...; end`` commands (:issue:`6415`).
New or improved bindings
^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -279,4 +279,8 @@ enum class pipeline_position_t {
#define ERROR_TIME_BACKGROUND \
_(L"'time' is not supported for background jobs. Consider using 'command time'.")
/// Error issued on { echo; echo }.
#define ERROR_NO_BRACE_GROUPING \
_(L"'{ ... }' is not supported for grouping commands. Please use 'begin; ...; end'")
#endif

View File

@ -779,6 +779,10 @@ end_execution_reason_t parse_execution_context_t::handle_command_not_found(
}
}
if (!cmd_str.empty() && cmd_str.at(0) == L'{') {
error.append(ERROR_NO_BRACE_GROUPING);
}
// Here we want to report an error (so it shows a backtrace).
// If the handler printed text, that's already shown, so error will be empty.
return this->report_error(STATUS_CMD_UNKNOWN, statement, error.c_str());

View File

@ -21,4 +21,10 @@ $fish -C 'functions --erase fish_command_not_found' -c 'nonexistent-command appl
#CHECKERR: nonexistent-command apple friday
#CHECKERR: ^
{ echo; echo }
# CHECKERR: {{.*}}: Unknown command: '{ echo; echo }'
# CHECKERR: {{.*}}: '{ ... }' is not supported for grouping commands. Please use 'begin; ...; end'
# CHECKERR: { echo; echo }
# CHECKERR: ^
exit 0