From: Ray Andrews <rayandrews@eastlink.ca>
To: zsh-users@zsh.org
Subject: Re: path PATH
Date: Fri, 27 Jan 2023 16:12:35 -0800 [thread overview]
Message-ID: <d938bc92-3691-957c-bb56-91d7c1713d58@eastlink.ca> (raw)
In-Reply-To: <1a232406-ad76-b661-496b-974ddf8e67fe@ckhb.org>
On 2023-01-27 15:45, scowles@ckhb.org 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!
next prev parent reply other threads:[~2023-01-28 0:13 UTC|newest]
Thread overview: 119+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-20 21:57 Ray Andrews
2023-01-20 22:20 ` Bart Schaefer
2023-01-21 2:23 ` Ray Andrews
2023-01-21 6:11 ` Lawrence Velázquez
2023-01-21 15:18 ` Ray Andrews
2023-01-21 15:25 ` Roman Perepelitsa
2023-01-21 16:21 ` Ray Andrews
2023-01-21 16:38 ` Roman Perepelitsa
2023-01-21 16:54 ` Ray Andrews
2023-01-21 17:01 ` Roman Perepelitsa
2023-01-21 18:53 ` Ray Andrews
2023-01-21 19:09 ` Roman Perepelitsa
2023-01-21 20:50 ` Ray Andrews
2023-01-21 21:11 ` Roman Perepelitsa
2023-01-21 20:19 ` Bart Schaefer
2023-01-21 20:26 ` env arrays (was: Re: path PATH) zeurkous
2023-01-22 17:28 ` Bart Schaefer
2023-01-21 21:03 ` path PATH Ray Andrews
2023-01-21 21:52 ` Lawrence Velázquez
2023-01-22 0:42 ` Ray Andrews
2023-01-22 12:29 ` Roman Perepelitsa
2023-01-22 14:17 ` Ray Andrews
2023-01-22 16:15 ` Bart Schaefer
2023-01-22 17:23 ` Ray Andrews
2023-01-22 19:20 ` Bart Schaefer
2023-01-22 19:31 ` Roman Perepelitsa
2023-01-22 19:51 ` Bart Schaefer
2023-01-22 19:56 ` Roman Perepelitsa
2023-01-22 20:03 ` Bart Schaefer
2023-01-22 21:56 ` Bart Schaefer
2023-01-22 22:02 ` Roman Perepelitsa
2023-01-22 22:27 ` Bart Schaefer
2023-01-22 23:03 ` Ray Andrews
2023-01-22 20:12 ` Ray Andrews
2023-01-22 21:11 ` Bart Schaefer
2023-01-22 22:44 ` Ray Andrews
2023-01-22 23:35 ` Lawrence Velázquez
2023-01-22 23:58 ` Ray Andrews
2023-01-23 0:49 ` Lawrence Velázquez
2023-01-23 1:33 ` Bart Schaefer
2023-01-23 1:49 ` Lawrence Velázquez
2023-01-23 1:11 ` Bart Schaefer
2023-01-23 1:56 ` Ray Andrews
2023-01-23 2:59 ` Lawrence Velázquez
2023-01-23 3:47 ` Ray Andrews
2023-01-23 10:37 ` Roman Perepelitsa
2023-01-23 15:28 ` Ray Andrews
2023-01-23 15:40 ` zeurkous
2023-01-23 16:02 ` Ray Andrews
2023-01-23 16:25 ` zeurkous
2023-01-23 16:26 ` Bart Schaefer
2023-01-24 20:00 ` Ray Andrews
2023-01-24 20:42 ` Bart Schaefer
2023-01-24 20:50 ` Bart Schaefer
2023-01-24 20:54 ` Ray Andrews
2023-01-24 23:28 ` Ray Andrews
2023-01-24 23:42 ` Bart Schaefer
2023-01-25 0:14 ` Ray Andrews
2023-01-25 16:38 ` Ray Andrews
2023-01-25 16:43 ` Roman Perepelitsa
2023-01-25 16:56 ` Ray Andrews
2023-01-25 17:02 ` Roman Perepelitsa
2023-01-25 17:34 ` Ray Andrews
2023-01-25 17:37 ` Roman Perepelitsa
2023-01-25 18:26 ` Ray Andrews
2023-01-25 18:34 ` Roman Perepelitsa
2023-01-25 19:00 ` Ray Andrews
2023-01-26 2:13 ` Ray Andrews
2023-01-26 2:37 ` Bart Schaefer
2023-01-26 4:27 ` Ray Andrews
2023-01-26 20:26 ` Ray Andrews
2023-01-26 20:29 ` Roman Perepelitsa
2023-01-26 20:59 ` Ray Andrews
2023-01-26 21:17 ` Bart Schaefer
2023-01-26 21:41 ` Bart Schaefer
2023-01-26 21:44 ` Bart Schaefer
2023-01-26 22:36 ` Ray Andrews
2023-01-26 22:43 ` Bart Schaefer
2023-01-27 0:19 ` Ray Andrews
2023-01-27 3:36 ` Ray Andrews
2023-01-27 17:51 ` Ray Andrews
2023-01-27 20:45 ` Bart Schaefer
2023-01-27 21:09 ` Ray Andrews
2023-01-27 23:45 ` scowles
2023-01-28 0:12 ` Ray Andrews [this message]
2023-01-28 3:47 ` Bart Schaefer
2023-01-28 16:42 ` Ray Andrews
2023-01-28 22:51 ` Bart Schaefer
2023-01-29 2:30 ` Ray Andrews
2023-01-29 3:03 ` Bart Schaefer
2023-01-29 3:44 ` Ray Andrews
2023-01-29 4:35 ` Bart Schaefer
2023-01-29 15:54 ` Ray Andrews
2023-01-29 21:21 ` Lawrence Velázquez
2023-01-29 22:33 ` Ray Andrews
2023-01-29 22:42 ` Lawrence Velázquez
2023-01-30 0:42 ` Ray Andrews
2023-01-30 0:46 ` Ray Andrews
2023-01-30 4:41 ` Bart Schaefer
2023-01-30 5:16 ` Lawrence Velázquez
2023-01-30 6:55 ` Bart Schaefer
2023-01-30 14:40 ` Ray Andrews
2023-01-30 14:55 ` Ray Andrews
2023-01-30 14:56 ` Roman Perepelitsa
2023-01-30 15:56 ` Ray Andrews
2023-01-30 16:09 ` Roman Perepelitsa
2023-01-30 16:24 ` Bart Schaefer
2023-01-30 16:34 ` Roman Perepelitsa
2023-01-30 23:05 ` Ray Andrews
2023-01-30 17:50 ` Bart Schaefer
2023-01-31 0:42 ` Ray Andrews
2023-01-26 22:18 ` Ray Andrews
2023-01-25 22:18 ` Bart Schaefer
2023-01-25 23:10 ` Ray Andrews
2023-01-25 23:19 ` Bart Schaefer
2023-01-26 0:55 ` Ray Andrews
2023-01-22 19:52 ` Ray Andrews
2023-01-21 16:48 ` Bart Schaefer
2023-01-21 5:47 ` Lawrence Velázquez
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=d938bc92-3691-957c-bb56-91d7c1713d58@eastlink.ca \
--to=rayandrews@eastlink.ca \
--cc=zsh-users@zsh.org \
/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).