Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
how to show all parms matching a given substring?
- X-seq: zsh-users 8156
- From: "S. Cowles" <scowles@xxxxxxxxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: how to show all parms matching a given substring?
- Date: Wed, 3 Nov 2004 14:47:46 -0800
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- Organization: personal
- Reply-to: scowles@xxxxxxxxxxxxx
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
}
Messages sorted by:
Reverse Date,
Date,
Thread,
Author