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

Re: Prevent a specific function from being xtrace'd



Bart Schaefer wrote on Mon, Aug 23, 2021 at 13:04:42 -0700:
> On Mon, Aug 23, 2021 at 9:42 AM Zach Riggle <zachriggle@xxxxxxxxx> wrote:
> >
> > Hello all!
> >
> > ~~ TL; DR ~~
> > Is there any way to mark or annotate a function such that its internals should not be traced, even if "set -x" or "zsh -x" is used?
> 
> emulate zsh +x -c 'autoload untraced'
> 
> (The name "untraced" is for example, not some sort of extra magic.)
> It also works for
> 
> emulate zsh +x -c 'untraced() { ... }'
> 
> but that requires that you're careful about quoting in the function body.
> 
> Of course you can still force tracing back on with
>   functions -t untraced
> or the function internally calling "set -x" etc.

Another idea: instead of «set -x» globally, use «functions -T» on every
function except the ones you don't want to trace, as in:

[[[
% f() { g }
% g() { h }
% h() { pwd }
% functions -mT '*' 
% functions +T g 
% f
+f:7> g
+h:7> pwd
/home/daniel
]]]

This won't apply tracing to top-level code (outside of a function).




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