Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: following a variable's value.
On Sat, Oct 17, 2015 at 4:40 PM, Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
> Gentlemen,
>
> I discovered by accident the useful 'warncreateglobal' and it has me in mind
> to ask if there's some way of tracing the value of variable. I know about
> 'set -x' of course, but some way of following the fortunes of a single
> variable would be very nice.
Take a look at traps for the DEBUG pseudo-signal. The simplest
formulation might look something like this:
unsetopt debug_before_cmd
typeset -ga var_watchlist
TRAPDEBUG() { (( $#var_watchlist )) && typeset -m "${var_watchlist[@]}" }
Now after every command you'll see the value of whatever variables are
named in $var_watchlist.
Left as an exercise is to store the current value somewhere and only
print the new value when it changes. Once you've done that, then it
should further be easy to print something when the variable becomes
unset.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author