Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: following a variable's value.

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

Messages sorted by: Reverse Date, Date, Thread, Author