zsh-users
 help / color / mirror / code / Atom feed
* following a variable's value.
@ 2015-10-17 23:40 Ray Andrews
  2015-10-18  0:29 ` ZyX
  2015-10-18 16:54 ` Bart Schaefer
  0 siblings, 2 replies; 8+ messages in thread
From: Ray Andrews @ 2015-10-17 23:40 UTC (permalink / raw)
  To: Zsh Users

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.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: following a variable's value.
  2015-10-17 23:40 following a variable's value Ray Andrews
@ 2015-10-18  0:29 ` ZyX
  2015-10-18  4:31   ` Ray Andrews
  2015-10-18 16:54 ` Bart Schaefer
  1 sibling, 1 reply; 8+ messages in thread
From: ZyX @ 2015-10-18  0:29 UTC (permalink / raw)
  To: Ray Andrews, Zsh Users

18.10.2015, 03:11, "Ray Andrews" <rayandrews@eastlink.ca>:
> 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.

I personally know only one way: create a C module which will create a special variable which will run some method each time variable is assigned. Partially you can do it with my https://bitbucket.org/ZyX_I/zpython, but this is rather limited:

1. You are bound to a single variable type. Type can be any: integer, float, string, array, associative array, but only one. Type may only be changed by unsetting the variable and creating a new one.
2. Variable name must start with a $zpython_.
3. Setting non-hash variables is using rather strange convention: zpython_string=foo will call `{bound_object}.__call__('foo')` (essentially the same thing as `{bound_object}('foo')`). This is because normally such types are immutable (hashes can be mutated in-place and zpython uses corresponding methods in place of `__call__`). Do not remember why I choosed not to use standard sequence protocol for editing arrays in addition to hashes, some of which may also be mutated (like list() type).

Also I am not really sure whether calling zsh code from parameter handlers is a safe operation, as well as querying any specific operation.

If you write C module specifically for your needs you may overcome these limitations.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: following a variable's value.
  2015-10-18  0:29 ` ZyX
@ 2015-10-18  4:31   ` Ray Andrews
  2015-10-18 11:19     ` ZyX
  0 siblings, 1 reply; 8+ messages in thread
From: Ray Andrews @ 2015-10-18  4:31 UTC (permalink / raw)
  To: zsh-users

On 10/17/2015 05:29 PM, ZyX wrote:
> 18.10.2015, 03:11, "Ray Andrews" <rayandrews@eastlink.ca>:
>> 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.
...
> If you write C module specifically for your needs you may overcome these limitations.
>
Thanks ZyX, but that sounds way over my head.  I've still never touched 
python.  If no  one else has any ideas then I'll keep doing it the hard 
way with inserted queries.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: following a variable's value.
  2015-10-18  4:31   ` Ray Andrews
@ 2015-10-18 11:19     ` ZyX
  2015-10-18 17:15       ` Ray Andrews
  0 siblings, 1 reply; 8+ messages in thread
From: ZyX @ 2015-10-18 11:19 UTC (permalink / raw)
  To: Ray Andrews, zsh-users

18.10.2015, 07:33, "Ray Andrews" <rayandrews@eastlink.ca>:
> On 10/17/2015 05:29 PM, ZyX wrote:
>>  18.10.2015, 03:11, "Ray Andrews" <rayandrews@eastlink.ca>:
>>>  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.
>
> ...
>>  If you write C module specifically for your needs you may overcome these limitations.
>
> Thanks ZyX, but that sounds way over my head. I've still never touched
> python. If no one else has any ideas then I'll keep doing it the hard
> way with inserted queries.

You can use some other languages which allow compiling *.so libraries and have a way to create compatible ABI: e.g. Rust. But in any case basic C knowledge is necessary.

What do you mean by “inserted queries”? Some kind of “debugging printf”?


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: following a variable's value.
  2015-10-17 23:40 following a variable's value Ray Andrews
  2015-10-18  0:29 ` ZyX
@ 2015-10-18 16:54 ` Bart Schaefer
  1 sibling, 0 replies; 8+ messages in thread
From: Bart Schaefer @ 2015-10-18 16:54 UTC (permalink / raw)
  To: Ray Andrews; +Cc: Zsh Users

On Sat, Oct 17, 2015 at 4:40 PM, Ray Andrews <rayandrews@eastlink.ca> 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.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: following a variable's value.
  2015-10-18 11:19     ` ZyX
@ 2015-10-18 17:15       ` Ray Andrews
  2015-10-18 17:33         ` Bart Schaefer
  0 siblings, 1 reply; 8+ messages in thread
From: Ray Andrews @ 2015-10-18 17:15 UTC (permalink / raw)
  To: zsh-users

On 10/18/2015 04:19 AM, ZyX wrote:

> What do you mean by “inserted queries”? Some kind of “debugging printf”? 

Sure, things like:

     echo "line 793: REPLY is $REPLY" >> /dev/pts/1

How convenient it would be to have a running tab on a variable.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: following a variable's value.
  2015-10-18 17:15       ` Ray Andrews
@ 2015-10-18 17:33         ` Bart Schaefer
  2015-10-18 17:46           ` Ray Andrews
  0 siblings, 1 reply; 8+ messages in thread
From: Bart Schaefer @ 2015-10-18 17:33 UTC (permalink / raw)
  To: Zsh Users

> How convenient it would be to have a running tab on a variable.

You might also look at https://github.com/rocky/zshdb


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: following a variable's value.
  2015-10-18 17:33         ` Bart Schaefer
@ 2015-10-18 17:46           ` Ray Andrews
  0 siblings, 0 replies; 8+ messages in thread
From: Ray Andrews @ 2015-10-18 17:46 UTC (permalink / raw)
  To: zsh-users

On 10/18/2015 10:33 AM, Bart Schaefer wrote:
>> How convenient it would be to have a running tab on a variable.
> You might also look at https://github.com/rocky/zshdb
>
Thanks for both suggestions, I'll take a look.


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2015-10-18 17:46 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-17 23:40 following a variable's value Ray Andrews
2015-10-18  0:29 ` ZyX
2015-10-18  4:31   ` Ray Andrews
2015-10-18 11:19     ` ZyX
2015-10-18 17:15       ` Ray Andrews
2015-10-18 17:33         ` Bart Schaefer
2015-10-18 17:46           ` Ray Andrews
2015-10-18 16:54 ` Bart Schaefer

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).