From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5873 invoked from network); 3 Sep 2004 16:37:38 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 3 Sep 2004 16:37:38 -0000 Received: (qmail 79318 invoked from network); 3 Sep 2004 16:37:33 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 3 Sep 2004 16:37:33 -0000 Received: (qmail 3937 invoked by alias); 3 Sep 2004 16:36:51 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 7969 Received: (qmail 3927 invoked from network); 3 Sep 2004 16:36:50 -0000 Received: from unknown (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 3 Sep 2004 16:36:50 -0000 Received: (qmail 77784 invoked from network); 3 Sep 2004 16:35:51 -0000 Received: from madrid10.amenworld.com (62.193.203.32) by a.mx.sunsite.dk with SMTP; 3 Sep 2004 16:35:49 -0000 Received: from DervishD.pleyades.net (212.Red-80-35-44.pooles.rima-tde.net [80.35.44.212]) by madrid10.amenworld.com (8.10.2/8.10.2) with ESMTP id i83GZj114973 for ; Fri, 3 Sep 2004 18:35:45 +0200 Received: from disposable1@telefonica.net by DervishD.pleyades.net with local (Exim MTA 2.05) id <1C3H1p-0003Hi-00>; Fri, 3 Sep 2004 18:35:09 +0200 Date: Fri, 3 Sep 2004 18:35:09 +0200 From: DervishD To: Zsh Users Subject: Making a script 'sourceable' Message-ID: <20040903163509.GA12618@DervishD> Mail-Followup-To: Zsh Users Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit User-Agent: Mutt/1.4.2.1i Organization: Pleyades X-Spam-Checker-Version: SpamAssassin 2.63 on a.mx.sunsite.dk X-Spam-Level: X-Spam-Status: No, hits=-0.0 required=6.0 tests=BAYES_44 autolearn=no version=2.63 X-Spam-Hits: -0.0 Hi all :) Last month I asked here how to detect, portably, whether a script had been sourced, and since then I've tried, with no success. That given, I'm trying to do two things. First one is detecting the 'sourcing' non portably, in zsh. Checking for $SHLVL doesn't work, because the user could have launched a new instance of zsh and so SHLVL will appear increased even when sourceing. So what I'm 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... 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. I thought that simply doing 'emulate -L zsh' will do, since any change to options and values will remain local to the script, but it won't work when sourceing because the script is run in the current environment :( So I must, by hand, restore any changed variables, options and, what more? Must I restore any other thing? Is there any simple way of making scripts source-safe or source-aware? Thanks a lot in advance :) Raúl Núñez de Arenas Coronado -- Linux Registered User 88736 http://www.pleyades.net & http://raul.pleyades.net/