zsh-users
 help / color / mirror / code / Atom feed
From: "S. Cowles" <scowles@earthlink.net>
To: zsh-users@sunsite.dk
Subject: how to show all parms matching a given substring?
Date: Wed, 3 Nov 2004 14:47:46 -0800	[thread overview]
Message-ID: <200411031447.50010.scowles@earthlink.net> (raw)


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
}



             reply	other threads:[~2004-11-03 22:49 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-11-03 22:47 S. Cowles [this message]
2004-11-04  2:53 ` Bart Schaefer
2004-11-04  4:15   ` S. Cowles

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200411031447.50010.scowles@earthlink.net \
    --to=scowles@earthlink.net \
    --cc=zsh-users@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).