Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: path PATH



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.

>       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.

>       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}
(where I'm not even sure the (q) is necessary).

>       fi
>     }

[...]

> If you want to describe all parameters, you can do it like this:
>
>     for name in ${(k)parameters}; do
>       describe-param $name
>     done

If the $parameters array is thrown in to the function itself, we can
make describe-param accept multiple names and patterns.

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
}

Now describing all parameters is just

  describe-params '*'

and it'll also handle

  describe-params '*(#i)path' '(#i)zsh*'

etc.




Messages sorted by: Reverse Date, Date, Thread, Author