Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: path PATH
On Sun, Jan 22, 2023 at 8:20 PM Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
>
> On Sun, Jan 22, 2023 at 4:30 AM Roman Perepelitsa
> <roman.perepelitsa@xxxxxxxxx> wrote:
> >
> > describe-param() {
> > emulate -L zsh
> > [[ ARGC -eq 1 && -n $1 ]] || return
> > set -- "$@" ${(Pt)1}
> > [[ -$2- == *-hide-* ]] && return 1
>
> I'm curious why you chose to do this? The "hide" attribute means that
> a local does not preserve semantics of a special global, not that it's
> name is invisible.
That's a brainfart on my part. I even know what "hide" means but
somehow I've coded it as if it meant something else.
> > print -rn -- "$2 ${(q-)1}"
> > if [[ -$2- == *-hideval-* ]]; then
> > print
>
> I'd guess that Ray would prefer to see the value even if it's normally
> hidden by "set" but this is more consistent.
I mainly added this after seeing just how much output there is if you
print values of all parameters. Made me appreciate the fact that
`typeset` doesn't print those.
> > else
> > set -- "$@" ${(M)2:#(array|association)(|-*)}
> > print -r -- "=${3:+( }${(j: :)${(@qqq)${(@kv)${(@P)1}}}}${3:+ )}"
>
> If you leave off the "${(q-)1}" in the earlier "print -rn", I think this is just
> typeset -m ${(q)1}
Oh, I only now realized that the output of `typeset -m` isn't the same
as of `typeset -p` (I now see that you've pointed this out in earlier
emails but I missed it). This is definitely an improvement to the code
but makes me wonder whether it's a good thing that typeset behaves
this way. Intuitively, I expected that `typeset -m pat` is equivalent
to `typeset -p [params]..` where `[params]..` is the names of all
parameters matching `pat`.
> (where I'm not even sure the (q) is necessary).
I think it should be (b).
> describe-params () {
> emulate -L zsh -o extendedglob
> zmodload zsh/parameter
> set -- ${(ok)parameters[(I)${~${(j.|.)@}}]}
> while ((ARGC))
> do
> print -rn -- "${parameters[$1]} "
> if [[ -${parameters[$1]}- = *-hideval-* ]]
> then
> print -r -- ${(q-)1}
> else
> typeset -m ${(q)1}
> fi
> shift
> done
> }
This looks great! Simpler and more powerful than my version.
Roman.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author