zsh-users
 help / color / mirror / code / Atom feed
* Understanding why...
@ 2017-08-07 23:46 Clint Priest
  2017-08-08  0:36 ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Clint Priest @ 2017-08-07 23:46 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 1290 bytes --]

Hello,

I'm new to the list and to ZSH, long time bash user though.

I was writing a function which would convert the LS_COLORS entry to an 
associative array.

I have solved the issue but I'd like to understand why it was 
necessary.  I'll take an answer from someone here, but what I'd really 
like to find out is if there is *some sort of 'set -x' functionality 
that would give me verbose information *about what is going on.

So, given:

LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=01;05;37;41:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:

This gave me the results I wanted:

typeset-A LSC=(${(@s/=/)${(@s/:/)${LS_COLORS%:}}})


What it needed was the two @ flags.  I'd like to understand just what is 
going on in each step of the expansion that required those two flags.

Thanks for any help!

-Clint

-- 

-Clint


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Understanding why...
  2017-08-07 23:46 Understanding why Clint Priest
@ 2017-08-08  0:36 ` Bart Schaefer
  2017-08-08  1:26   ` Clint Priest
  0 siblings, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 2017-08-08  0:36 UTC (permalink / raw)
  To: Clint Priest; +Cc: Zsh Users

On Mon, Aug 7, 2017 at 4:46 PM, Clint Priest <cpriest@zsh-users.rxv.me> wrote:
>
> I'll take an answer from someone here, but what I'd really like to find out
> is if there is *some sort of 'set -x' functionality that would give me
> verbose information *about what is going on.

No, there's no trace setting that would reveal the inner workings of
parameter expansion.  Your best bet is to look at the documentation,
e.g., search for the string "Rules" in "man zshexpn".

> typeset-A LSC=(${(@s/=/)${(@s/:/)${LS_COLORS%:}}})
>
> What it needed was the two @ flags.  I'd like to understand just what is
> going on in each step of the expansion that required those two flags.

The short answer is that a nested expansion by default joins arrays on
the first character of $IFS and yields a scalar result.  The @ is
necessary to indicate that you want array-ness to be preserved.  It's
actually the OUTER ${...} that enforces joining on the INNER
expression, so in the above you only need the leftmost @ so that s/:/
isn't re-joined before s/=/ applies; but the second @ doesn't hurt.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Understanding why...
  2017-08-08  0:36 ` Bart Schaefer
@ 2017-08-08  1:26   ` Clint Priest
  2017-08-08  5:25     ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Clint Priest @ 2017-08-08  1:26 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 1697 bytes --]

Interesting, when you say by default, is that an option that can be changed?

Thanks for that tidbit, any chance you know in the manual whereabouts it 
talks about this inner splitting and outer preservation?

Also (and I had tried to do this), is it possible to break out the 
nested expansions into their separate parts to see what is going on (via 
trace)?

I had tried that but it seemed that some zsh specific lines weren't 
showing (could have been because some of them where just variable sets, 
sans a typeset).

Thanks Much!

On 8/7/2017 7:36 PM, Bart Schaefer wrote:
> On Mon, Aug 7, 2017 at 4:46 PM, Clint Priest <cpriest@zsh-users.rxv.me> wrote:
>> I'll take an answer from someone here, but what I'd really like to find out
>> is if there is *some sort of 'set -x' functionality that would give me
>> verbose information *about what is going on.
> No, there's no trace setting that would reveal the inner workings of
> parameter expansion.  Your best bet is to look at the documentation,
> e.g., search for the string "Rules" in "man zshexpn".
>
>> typeset-A LSC=(${(@s/=/)${(@s/:/)${LS_COLORS%:}}})
>>
>> What it needed was the two @ flags.  I'd like to understand just what is
>> going on in each step of the expansion that required those two flags.
> The short answer is that a nested expansion by default joins arrays on
> the first character of $IFS and yields a scalar result.  The @ is
> necessary to indicate that you want array-ness to be preserved.  It's
> actually the OUTER ${...} that enforces joining on the INNER
> expression, so in the above you only need the leftmost @ so that s/:/
> isn't re-joined before s/=/ applies; but the second @ doesn't hurt.

-- 

-Clint


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Understanding why...
  2017-08-08  1:26   ` Clint Priest
@ 2017-08-08  5:25     ` Bart Schaefer
  0 siblings, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2017-08-08  5:25 UTC (permalink / raw)
  To: Clint Priest; +Cc: Zsh Users

On Mon, Aug 7, 2017 at 6:26 PM, Clint Priest <cpriest@zsh-users.rxv.me> wrote:
> Interesting, when you say by default, is that an option that can be changed?

When I say "by default", I mean "you change it by adding (@)".

> Thanks for that tidbit, any chance you know in the manual whereabouts it
> talks about this inner splitting and outer preservation?

>> On 8/7/2017 7:36 PM, Bart Schaefer wrote:
>> e.g., search for the string "Rules" in "man zshexpn".

> Also (and I had tried to do this), is it possible to break out the nested
> expansions into their separate parts to see what is going on (via trace)?

Sure; setopt xtrace and then compare

: ${(s/:/)${LS_COLORS%:}}
: ${(s/=/)${(s/:/)${LS_COLORS%:}}}
: ${(@s/=/)${(s/:/)${LS_COLORS%:}}}

(where ":" is the no-op command that discards its arguments)


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-08-08  5:25 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-07 23:46 Understanding why Clint Priest
2017-08-08  0:36 ` Bart Schaefer
2017-08-08  1:26   ` Clint Priest
2017-08-08  5:25     ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).