Support help argument in "{ -h"

Unlike other builtins, "{" is a separate token, not a keyword-string
token.

Allow the left brace token as command string; produce it when parsing
"{ -h"/"{ --help" (and nowhere else).  By using a decorated statement,
we reuse logic for redirections etc.

Other syntax elements like "and" are in the builtin list, which
- adds highlighting logic
- adds it to "builtin --names"
- makes it runnable as builtin
  (e.g. "builtin '{'" would hypothetically print the man page)

These don't seem very important (highlighting for '{' needs to match
'}' anyway).

Additionally, making it a real builtin would mean that we'd need to
deactivate a few places that unescape "{" to BRACE_BEGIN.

Let's not add it to the built in list. Instead, simply synthesize
builtin_generic in the right spot.

I'm assuming we want "{ -h" to print help, but '"{" -h' to run an
external command, since the latter is historical behavior.  This works
naturally with the above fake builtin approach which never tries to
unescape the left brace.
This commit is contained in:
Johannes Altmanninger
2025-01-13 06:25:35 +01:00
parent f26ebac8dd
commit efce176ceb
11 changed files with 180 additions and 25 deletions

View File

@@ -8,6 +8,8 @@ function __fish_print_help --description "Print help message for the specified f
set item true
case '['
set item test
case '{'
set item begin
end
# Do nothing if the file does not exist