Open georgebrock opened 5 years ago
I've been using this version for a few days, and I think I want to revisit some of the deliberate differences from how GNU Bash et al. handle things. Specifically these two:
- Single-option expansions behave like strings, e.g.
{x}
is like'x'
.- Zero-option expansions behave like empty strings, e.g.
{}
is like''
.
I'll frequently diff my local branch against upstream, e.g. after a complex interactive rebase to make sure I didn't introduce accidental changes. The easiest way I know of doing that is diff @{u} @
. After this change, that's pretty cumbersome (either diff '@{u}' @
or diff @\{u\}
).
There are other similar shorthands, which I use less often but others might not, like @{-1}
.
Three solutions I can think of:
{}
or {x}
as literals, only doing expansion when there's at least one comma.$_u
, and advise gitsh users to use that.diff @{u} @
to diffu
for my own use case, and trust others will find similar work arounds.Following the principal of least astonishment, I'm inclined to do the first one.
What do other gitsh users things? /cc @sharplet @mike-burns
Huh I had no idea:
~% echo a.{b,c}
a.b a.c
~% echo a.{b}
a.{b}
~% echo a.{}
a.{}
(zsh)
I'm in favor of that, option (1).
I’m also in favour of option 1. I regularly use this syntax to inspect my stash
:
git show stash@{1} # show me the next stash below the top
Finally got back to this and (pairing with @seanpdoyle) figured out how to make this behave more like general-purpose shells. As of now:
{a,b}1
is equivalent to a1 b1
@{u}
is a literal argument{}
is a literal argumentWe had to make some minor compromises to get there, specifically an unmatched brace is now a parse error, but it's possible to work around by using an escaped brace e.g.
gitsh@ :echo }
gitsh: parse error
gitsh@ :echo \}
}
e.g.
:echo h{i,o}p
produceship hop
.The implementation differs from GNU Bash and other general purpose shells in a few ways. First, there are a few deliberate things that I think improve the consistency of the language:
{x}
is like'x'
.{}
is like''
.There are also a couple of differences that we might want to consider changing:
echo $FOO{1,2}
is likeecho $FOO1 $FOO2
(butecho ${FOO1,FOO2}
is an error).To support this new behaviour this PR also updates all of the various
Gitsh::Arguments::*
classes'#value
methods to produce Arrays instead of single values. TheGitsh::ArgumentList
class takes on the responsibility of flattening the results.Begins to address #145