zsh-users
 help / color / mirror / code / Atom feed
* Global xtrace from function
@ 2014-07-20 15:20 Thorsten Kampe
  2014-07-20 16:09 ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: Thorsten Kampe @ 2014-07-20 15:20 UTC (permalink / raw)
  To: zsh-users

Hi,

is it possible to `setopt xtrace` from within a function without 
having xtrace unset when exiting the function? That seems to be the 
default behaviour for Bash's `shopt -os xtrace`.

Thorsten



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

* Re: Global xtrace from function
  2014-07-20 15:20 Global xtrace from function Thorsten Kampe
@ 2014-07-20 16:09 ` Bart Schaefer
  2014-07-20 16:20   ` Thorsten Kampe
  0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2014-07-20 16:09 UTC (permalink / raw)
  To: zsh-users

On Jul 20,  5:20pm, Thorsten Kampe wrote:
}
} is it possible to `setopt xtrace` from within a function without 
} having xtrace unset when exiting the function? That seems to be the 
} default behaviour for Bash's `shopt -os xtrace`.

The options XTRACE, PRINT_EXIT_VALUE, LOCAL_OPTIONS, and LOCAL_LOOPS
are always reset on exit from a function.  (I'm not sure why the
LOCAL_TRAPS and LOCAL_PATTERNS options aren't in that list as well,
except "because they're newer and nobody thought of it.")  Zsh has
behaved this way since before the source was under version control.

It's possible that we ought to skip resetting xtrace when in posix
shell emulation mode.

You can get the effect you want with

    this_sets_xtrace() { trap 'setopt xtrace' EXIT }

except of course in posix emulation (POSIX_TRAPS), when exit traps
aren't executed for shell functions ...


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

* Re: Global xtrace from function
  2014-07-20 16:09 ` Bart Schaefer
@ 2014-07-20 16:20   ` Thorsten Kampe
  0 siblings, 0 replies; 3+ messages in thread
From: Thorsten Kampe @ 2014-07-20 16:20 UTC (permalink / raw)
  To: zsh-users

* Bart Schaefer (Sun, 20 Jul 2014 09:09:10 -0700)
> 
> On Jul 20,  5:20pm, Thorsten Kampe wrote:
> }
> } is it possible to `setopt xtrace` from within a function without 
> } having xtrace unset when exiting the function? That seems to be the 
> } default behaviour for Bash's `shopt -os xtrace`.
> 
> The options XTRACE, PRINT_EXIT_VALUE, LOCAL_OPTIONS, and LOCAL_LOOPS
> are always reset on exit from a function.  (I'm not sure why the
> LOCAL_TRAPS and LOCAL_PATTERNS options aren't in that list as well,
> except "because they're newer and nobody thought of it.")  Zsh has
> behaved this way since before the source was under version control.
> 
> It's possible that we ought to skip resetting xtrace when in posix
> shell emulation mode.
> 
> You can get the effect you want with
> 
>     this_sets_xtrace() { trap 'setopt xtrace' EXIT }
> 
> except of course in posix emulation (POSIX_TRAPS), when exit traps
> aren't executed for shell functions ...

Works beautifully, thanks!


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

end of thread, other threads:[~2014-07-20 16:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-20 15:20 Global xtrace from function Thorsten Kampe
2014-07-20 16:09 ` Bart Schaefer
2014-07-20 16:20   ` Thorsten Kampe

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