Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: path PATH
On 2023-01-27 15:45, scowles@xxxxxxxx wrote:
as a lurker on the list, i am very grateful that you, ray, persevered
through this thread. if dp(){} has changed since yesterday, would you
mind posting your latest version?
The guts of it are almost exactly as Bart left it, but my version tarts
it up a little bit:
A few notes: 'infomsg' is just a colored message, 'echo' is fine. ${cyn}
is just the color code for cyan, and ${nrm} is the code for 'normal'. I
like colored output. As I have it, the accumulated output goes to a
variable instead of printing directly but the old code is there too.
And I've shortened the type-strings to single letters but that's easy to
cut out if you want. Oh, and I also truncate at screen width but that's
also easy to cut out. I Don't need to see those huge variables full length:
function v () # For 'variables'.
{
[[ "$1" = '-h' || "$1" = '-s' ]] && \
{
infomsg "
List attributes and values of all variables indicated by FILTER.
v ,CSsp [FILTER]
v ,C: SENS: (if FILTER is given).
v ,S: Show only if the value is not hidden.
v ,s: Show only if the value IS hidden.
v ,p: Plain, no color, this is good when the output needs to be sent to
a file.
FILTER: if given, is a pattern of variable names. If wildcards are
given then the argument must be quoted to avoid expansion by the shell.
TYPES: These are condensed from the detailed information you can see
like this: '$ print ${(t)path}'. Basic types are capitalized, modifiers
are in lower case:
S: An ordinary scalar (not an integer or float).
I: An integer.
F: A float ('typeset -F:' decimal display or 'typeset -E': scientific
display).
A: A normal array.
H: An associative array or 'association' or 'hash' (always 'hideval' as
well).
e: The variable has been exported to the environment and is thus
persistent within that terminal -- it will be inherited by subshells.
l: The variable is local to the running function.
t: The variable is 'tied' to another variable (see docs: 'typeset -T').
s: The variable is special to the shell.
r: The variable is read-only (this often goes with 'special').
v: 'hideval': the value of the variable will be hidden -- there are
things we really don't want to see, like lists of color codes. This
tends to go with 'special' and 'hide'.
h: Hide: Used with 'special' (see docs: 'typeset -h').
u: Unique: ??
?: Undefined: For autoloaded parameters not yet loaded (whatever that
means).
"
return
}
local ccolored=( sed -r "s/^(.{6})([^ = ]*)/\1${cyn}\2${nrm}/" )
local hhidden=( )
local case='(#i)'
local width=$(( COLUMNS - 5 ))
local line=
typeset -ga VARIABLES=()
if [[ ${1:0:1} == ',' ]]; then
for ((i=1; i < ${#1}; i++)); do
case ${1:$i:1} in
C ) case= ;; # Enable case sensitive.
p ) ccolored= ;; # 'plain': no color.
S ) hhidden=( grep -v ' = !hidden!' ) ;; # Show only if a
value is set.
s ) hhidden=( grep ' = !hidden!' ) ;; # Show only if a value is
NOT set.
* ) errormsg "No such switch \",${1:$i:1}\""; return 1 ;;
esac
done
shift
fi # End: process ',' switches.
# If a capital letter is given then force case sensitivity:
[[ $@ == *[[:upper:]]* ]] && case=
# Default is all params:
[ ! "$@" ] && set 1 '*'
set -- ${(ok)parameters[(I)${case}${~${(j.|.)@}}]}
while ((ARGC)); do
# Type eg: 'scalar '
# print -rn -- "${parameters[$1]} "
line+="${parameters[$1]} "
if [[ -${parameters[$1]}- = *-hideval-* ]]
then
# Append name and '=-hidden-'
# If param is hidden, typeset won't show anything so use this:
# print -r -- ${(q-)1}
line+="${(q-)1}=!hidden!"
else
# Append name and value eg: 'ZSH_VERSION=5.8':
# typeset -m -- ${(b)1}
line+=$( typeset -m -- ${(b)1} )
fi
VARIABLES+="$line"
line=
shift
done
echo
[ ! "$VARIABLES" ] && warningmsg "Nothing found" && return 1
print -rl -- $VARIABLES | sed \
-re "s/(^[^ ]*) ([^=]*)=(.*)/\1 \2 = \3/" \
-e "s/scalar[ |-]/S/" \
-e "s/integer[ |-]/I/" \
-e "s/float[ |-]/F/" \
-e "s/array[ |-]/A/" \
-e "s/association[ |-]/H/" \
-e "s/export[ |-]/e/" \
-e "s/local[ |-]/l/" \
-e "s/special[ |-]/s/" \
-e "s/readonly[ |-]/r/" \
-e "s/hideval[ |-]/v/" \
-e "s/hide[ |-]/h/" \
-e "s/tied[ |-]/t/" \
-e "s/unique[ |-]/u/" \
-e "s/undefined[ |-]/?/" \
-e "s/^([^ ]*)/\1 /" \
-e "s/^(.{6}) */\1/" \
-e "s/^(.{1,${width}}).*/\1/" \
-e "s/^(.{$width})/\1 .../" \
| ${ccolored:-cat} | ${hhidden:-cat}
} # END: v()
allvars ()
{
# Name and type:
print -l -- "\n${cyn}ALL VARIABLES AND THEIR TYPES:${nrm} \n"
printf "%-25s %s\n" ${(kv)parameters} | sort
# Types only:
# printf "%s\n" ${(v)parameters} | sort
}
nullvars ()
{
# emulate -L zsh -o extendedglob
nnullvars=()
for name in ${(k)parameters}; do
if [[ -z ${(P)name} ]]; then
# print -r -- $name
nnullvars+="$name"
fi
done
print -l -- "\n${cyn}NULL VARIABLES:${nrm} \n"
print -l -- "$nnullvars[@]" | sort
}
... hope you like it!
Messages sorted by:
Reverse Date,
Date,
Thread,
Author