Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Making a script 'sourceable'
- X-seq: zsh-users 7972
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxxxxx>
- Subject: Re: Making a script 'sourceable'
- Date: Fri, 3 Sep 2004 10:20:28 -0700 (PDT)
- In-reply-to: <20040903163509.GA12618@DervishD>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <20040903163509.GA12618@DervishD>
- Reply-to: zsh-users@xxxxxxxxxx
On Fri, 3 Sep 2004, DervishD wrote:
> That given, I'm trying to do two things. First one is detecting
> the 'sourcing' non portably, in zsh.
It can be done if setopt NO_FUNCTION_ARG_ZERO is in effect before the
script is sourced by comparing $0 either to $SHELL or to the name of
the script.
> thinking about now is to check the value of the option 'interactive'.
> If it is on, chances are that we have sourced the script. Otherwise,
> we may not. This is not perfect, though, because you can run a script
> (interactive=off) and then source the other script within...
If all your scripts check both the option and the state of $0 and then
explicitly turn off FUNCTION_ARG_ZERO, you're pretty much guaranteed to
catch direct sourcing the with the options and indirect sourcing with $0.
Other options you might check:
[[ -o SH_IN_STDIN ]]
[[ -o MONITOR ]]
> The second thing is derived from the above question: since
> checking for 'sourcery' ;) is very difficult even non portably, I've
> thought about making my zsh scripts sourceables.
Lloyd Z. has the way of it.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author