mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-30 03:01:15 -03:00
Always treat brace at command start as compound statement
For backwards compatibility, fish does not treat "{echo,hello}" as a compound
statement but as brace expansion (effectively "echo hello"). We interpret
"{X...}" as compound statement only if X is whitespace or ';' (which is an
interesting solution).
A brace expansion at the very start of a command
is usually pointless (space separation is shorter).
The exception are cases where the command name and the first few arguments
share a suffix.
$ {,1,2,3,4}echo
1echo 2echo 3echo 4echo
Not sure if anyone uses anything like that. Perhaps we want to trade
compatibility for simplicity. I don't have a strong opinion on this.
Always parse the opening brace as first character of a command token as
compound statement.
Brace expansion can still be used with a trick like: «''{echo,foo}»
Closes #11477
This commit is contained in:
@@ -67,26 +67,33 @@ e{cho,cho,cho}
|
||||
{ echo no semi }
|
||||
# CHECK: no semi
|
||||
|
||||
# Ambiguous cases
|
||||
{echo no space}
|
||||
# CHECK: no space
|
||||
|
||||
# Ambiguous case
|
||||
{ echo ,comma;}
|
||||
# CHECK: ,comma
|
||||
|
||||
PATH= {echo no space}
|
||||
# CHECKERR: fish: Unknown command: '{echo no space}'
|
||||
# CHECKERR: {{.*}}/braces.fish (line {{\d+}}):
|
||||
# CHECKERR: PATH= {echo no space}
|
||||
# CHECKERR: ^~~~~~~~~~~~~~^
|
||||
|
||||
PATH= {echo comma, no space;}
|
||||
# CHECKERR: fish: Unknown command: 'echo comma'
|
||||
# CHECKERR: {{.*}}/braces.fish (line {{\d+}}):
|
||||
# CHECKERR: PATH= {echo comma, no space;}
|
||||
# CHECKERR: ^~~~~~~~~~~~~~~~~~~~~~^
|
||||
# Ambiguous case with no trailing space
|
||||
{echo comma, no space;}
|
||||
# CHECK: comma, no space
|
||||
|
||||
# Ambiguous case with no space
|
||||
{echo,hello}
|
||||
# CHECK: hello
|
||||
PATH= {echo,hello}
|
||||
# CHECKERR: fish: Unknown command: echo,hello
|
||||
# CHECKERR: {{.*}}/braces.fish (line {{\d+}}):
|
||||
# CHECKERR: PATH= {echo,hello}
|
||||
# CHECKERR: ^~~~~~~~~^
|
||||
|
||||
function foo,
|
||||
echo foo,
|
||||
end
|
||||
function bar
|
||||
echo bar
|
||||
end
|
||||
{foo,;bar}
|
||||
# CHECK: foo,
|
||||
# CHECK: bar
|
||||
|
||||
# Trailing tokens
|
||||
set -l fish (status fish-path)
|
||||
@@ -157,7 +164,7 @@ end
|
||||
}
|
||||
# CHECK: while
|
||||
|
||||
{ { echo inner}
|
||||
{{echo inner}
|
||||
echo outer}
|
||||
# CHECK: inner
|
||||
# CHECK: outer
|
||||
@@ -172,9 +179,8 @@ complete foo -a '123 456'
|
||||
complete -C 'foo {' | sed 1q
|
||||
# CHECK: {{\{.*}}
|
||||
|
||||
complete -C '{'
|
||||
echo nothing
|
||||
# CHECK: nothing
|
||||
complete -C '{' | grep ^if\t
|
||||
# CHECK: if{{\t}}Evaluate block if condition is true
|
||||
complete -C '{ ' | grep ^if\t
|
||||
# CHECK: if{{\t}}Evaluate block if condition is true
|
||||
|
||||
|
||||
@@ -459,6 +459,9 @@ echo \\
|
||||
echo '{ { } }'
|
||||
# CHECK: { { } }
|
||||
|
||||
echo '{{}}'
|
||||
# CHECK: { { } }
|
||||
|
||||
echo '
|
||||
{
|
||||
|
||||
|
||||
Reference in New Issue
Block a user