Support FOO=bar syntax for passing variables to individual commands#6287
Conversation
|
The FAQ contains a question about this that would have to be removed.
|
11f4006 to
e80ceec
Compare
|
Rather than removing the entry, what about changing it to "Since fish 3.x, the |
|
I added this to the first FAQ entry, that should make sense but feel free to change it. |
|
A question is how we should handle bare "VAR=VALUE" without any command. Should we actually support |
|
Given the fact that fish already "supports" I often find myself following guides, studying online courses, or simply being sent shell snippets from colleagues that assume bare |
|
Adding support for We also need to settle on what to do when the value expands to multiple elements. $ export a=(printf 1\n2\n); printf %s, $a
2,
$ a=(printf 1\n2\n) printf %s, $a
1,2, |
|
My problem with bare |
ridiculousfish
left a comment
There was a problem hiding this comment.
Overall this is really fantastic - fits in nicely and well designed. This is thrilling!
I haven't fully finished reviewing the execution part yet; I expect it to change a bit if we take the grammar simplification which I suggest.
6e8d021 to
855ac7a
Compare
|
Looks great! Merge as you like. I don't have any strong feelings about the behavior of bare |
855ac7a to
87c25c8
Compare
This adds initial support for statements with prefixed variable assignments.
Statments like this are supported:
a=1 b=$a echo $b # outputs 1
Just like in other shells, the left-hand side of each assignment must
be a valid variable identifier (no quoting/escaping). Array indexing
(PATH[1]=/bin ls $PATH) is *not* yet supported, but can be added fairly
easily.
The right hand side may be any valid string token, like a command
substitution, or a brace expansion.
Since `a=* foo` is equivalent to `begin set -lx a *; foo; end`,
the assignment, like `set`, uses nullglob behavior, e.g. below command
can safely be used to check if a directory is empty.
x=/nothing/{,.}* test (count $x) -eq 0
Generic file completion is done after the equal sign, so for example
pressing tab after something like `HOME=/` completes files in the
root directory
Subcommand completion works, so something like
`GIT_DIR=repo.git and command git ` correctly calls git completions
(but the git completion does not use the variable as of now).
The variable assignment is highlighted like an argument.
Closes fish-shell#6048
87c25c8 to
4697e19
Compare
Since fish-shell#6287, bare variable assignments do not parse, which broke the "Unsupported use of '='" error message. This commit catches parse errors that occur on bare variable assignments. When a statement node fails to parse, then we check if there is at least one prefixing variable assignment. If so, we emit the old error message. See also fish-shell#6347
Since fish-shell#6287, bare variable assignments do not parse, which broke the "Unsupported use of '='" error message. This commit catches parse errors that occur on bare variable assignments. When a statement node fails to parse, then we check if there is at least one prefixing variable assignment. If so, we emit the old error message. See also fish-shell#6347
Since #6287, bare variable assignments do not parse, which broke the "Unsupported use of '='" error message. This commit catches parse errors that occur on bare variable assignments. When a statement node fails to parse, then we check if there is at least one prefixing variable assignment. If so, we emit the old error message. See also #6347
|
I'm not in a position to build fish at the moment, but one question that I don't think was raised in the original ticket: What's the behavior of a=foo b=$a echo $bIs |
|
|
This adds initial support for statements with prefixed variable assignments.
Statments like this are supported:
a=1 b=$a echo $b # outputs 1Just like in other shells, the left-hand side of each assignment must
be a valid variable identifier (no quoting/escaping). Array indexing
(
PATH[1]=/bin ls $PATH) is not yet supported, but can be added fairlyeasily.
The right hand side may be any valid string token, like a command
substitution, or a brace expansion.
Since
a=* foois equivalent tobegin set -lx a *; foo; end,the assignment, like
set, uses nullglob behavior, e.g. below commandcan safely be used to check if a directory is empty.
x=/nothing/{,.}* test (count $x) -eq 0Generic file completion is done after the equal sign, so for example
pressing tab after something like
HOME=/completes files in theroot directory
Subcommand completion works, so something like
GIT_DIR=repo.git and command gitcorrectly calls git completions(but the git completion does not use the variable as of now).
The variable assignment is highlighted like an argument.
Closes #6048
TODOs:
Follow-ups:
a=bexportshould work the same way