zsh-users
 help / color / mirror / code / Atom feed
* how to show all parms matching a given substring?
@ 2004-11-03 22:47 S. Cowles
  2004-11-04  2:53 ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: S. Cowles @ 2004-11-03 22:47 UTC (permalink / raw)
  To: zsh-users


I would like to solicit suggestions from others about a better, simpler way to 
get all parameters in the current context matching a given substring.  If 
this can be done using parameter expansion patterns, so much the better.

For right now, I use the following function.

Thanks,

scowles at earthlink dot net


showparms(){
  # find all parms with name or value matching a given fixed substring.

  availopts=hv
  usage="usage:  $0 -{${availopts}}"
  usage=$(printf "%s\n\t%s\n" $usage "h help")
  usage=$(printf "%s\n\t%s\n" $usage "v include parm values")

  v=""
  while getopts ":${availopts}" opt
  do
    case ${opt} in
      v )  v="v"
        ;;
      h )
        echo "${usage}" >&2
        return
        ;;
      \? )
        echo "invalid option usage." >&2
        echo ${OPTIND} >&2
        echo "${usage}" >&2
        return
        ;;
      \: )
        echo "missing option." >&2
        echo ${OPTIND} >&2
        echo "${usage}" >&2
        return
        ;;
    esac
  done
  shift $(( ${OPTIND} - 1 ))
  [[ -z "$1" ]] && {
    echo "must provide a pattern." >&2
    return
  }
  spatt="$1"

  [[ -z "${v}" ]] && {
    # work on parameter names, only.
    eval "
      showparm () {
        set + |
        while read line
        do
          [[ -z \"\${line}\" ]] && { continue ; }
          [[ \${line[(i)${spatt}]} -le \${#line} ]] && { echo \${line} ; }
        done
      }
    "
  }
  [[ -n "${v}" ]] && {
    # work on parameter names and values.
    eval "
      showparm () {
        set   |
        while read line
        do
          [[ -z \"\${line}\" ]] && { continue ; }

          [[ \${line[(i)${spatt}]} -le \${#line} &&
             \${line[(i)=]}        -le \${#line} ]] && { echo \${line} ; }
        done
      }
    "
  }
  showparm
}



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

* Re: how to show all parms matching a given substring?
  2004-11-03 22:47 how to show all parms matching a given substring? S. Cowles
@ 2004-11-04  2:53 ` Bart Schaefer
  2004-11-04  4:15   ` S. Cowles
  0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2004-11-04  2:53 UTC (permalink / raw)
  To: zsh-users

On Wed, 3 Nov 2004, S. Cowles wrote:

> I would like to solicit suggestions from others about a better, simpler 
> way to get all parameters in the current context matching a given 
> substring.  If this can be done using parameter expansion patterns, so 
> much the better.

The parameter names only case is just

	typeset +m ${spatt}

and the names-and-values case is

	print -l -- ${${(f)"$(typeset -x)"}:#${~spatt}}


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

* Re: how to show all parms matching a given substring?
  2004-11-04  2:53 ` Bart Schaefer
@ 2004-11-04  4:15   ` S. Cowles
  0 siblings, 0 replies; 3+ messages in thread
From: S. Cowles @ 2004-11-04  4:15 UTC (permalink / raw)
  To: zsh-users; +Cc: Bart Schaefer

On Wednesday 03 November 2004 18:53, Bart Schaefer wrote:
> On Wed, 3 Nov 2004, S. Cowles wrote:
> > I would like to solicit suggestions from others about a better, simpler
> > way to get all parameters in the current context matching a given
> > substring.  If this can be done using parameter expansion patterns, so
> > much the better.
>
> The parameter names only case is just
>
> 	typeset +m ${spatt}
>
> and the names-and-values case is
>
> 	print -l -- ${${(f)"$(typeset -x)"}:#${~spatt}}


Many thanks, Bart.


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

end of thread, other threads:[~2004-11-04  4:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-11-03 22:47 how to show all parms matching a given substring? S. Cowles
2004-11-04  2:53 ` Bart Schaefer
2004-11-04  4:15   ` S. Cowles

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