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

Re: path PATH



On Sun, Jan 22, 2023 at 1:42 AM Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
>
> I want to display the types too, and had hoped it would be possible, but it isn't so that's that.

Perhaps you can use something like this to describe parameters:

    describe-param() {
      emulate -L zsh
      [[ ARGC -eq 1 && -n $1 ]] || return
      set -- "$@" ${(Pt)1}
      [[ -$2- == *-hide-* ]] && return 1
      print -rn -- "$2 ${(q-)1}"
      if [[ -$2- == *-hideval-* ]]; then
        print
      else
        set -- "$@" ${(M)2:#(array|association)(|-*)}
        print -r -- "=${3:+( }${(j: :)${(@qqq)${(@kv)${(@P)1}}}}${3:+ )}"
      fi
    }

The output of this function is of the following shape:

    <TYPE> <NAME>[=<VALUE>]

For example:

    % describe-param PWD
    scalar-export PWD="/home/romka"

    % describe-param MAILCHECK
    integer MAILCHECK="60"

    % describe-param PATH
    scalar-tied-export-special PATH="/home/romka/bin:..."

    % describe-param path
    array-tied-unique-special path=( "/home/romka/bin" ... )

You might want to customize how the type is printed.

If you want to describe all parameters, you can do it like this:

    for name in ${(k)parameters}; do
      describe-param $name
    done

Roman.




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