Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: coloring a substitution
On Fri, Nov 11, 2022 at 11:25 PM Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
>
> On 2022-11-09 00:19, Roman Perepelitsa wrote:
> > Try this instead:
> > if [[ $scope_msg = 'BROAD' && $dirname = (#i)*$~1* ]] ||
> > [[ $scope_msg = 'Case INsensitive TAME' && $dirname = (#i)$~1 ]] ||
> > [[ $scope_msg = 'Case Sensitive WILD' && $dirname = *$~1* ]] ||
> > [[ $scope_msg = 'EXACT' && $dirname = $~1 ]]; then
> >
> That's in place Roman, works identically to mine and I'll keep it on
> your say so, but what are the fine points on why your lines are better?
These four cases are {case-sensitive, case-insensitive} x {full,
partial}. Moreover, the implementation of every case differs only on
these two bits: case insensitivity is always encoded as (#i) and
partial match always as *..*.
The only bizarre thing here is the names of these cases. They don't
reflect the simplicity of the code. The code is in fact so simple that
it's not obvious that it needs any cases other than 'EXACT': $1 can
have (#i) in it to make the match case-insensitive and *..* to make it
partial. It can even have the asterisk only one one side for prefix
and suffix matches.
> if [[ "$scope_msg" = 'BROAD' && $dirname =
> (#i)*$1* ]] \
> || [[ "$scope_msg" = 'Case INsensitive TAME' && $dirname:u = $1:u ]] \
> || [[ "$scope_msg" = 'Case Sensitive WILD' && $dirname =~ $1 ]] \
> || [[ "$scope_msg" = 'EXACT' && $dirname = $1 ]];
> then
Can you similarly describe these four cases, the way I've done in the
first paragraph above? I cannot. All four look uniquely different, so
the inventive names (BROAD, TAME, WILD, EXACT) almost look justified.
Roman.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author