From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3634 invoked from network); 17 Sep 2001 11:08:14 -0000 Received: from sunsite.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 17 Sep 2001 11:08:14 -0000 Received: (qmail 6455 invoked by alias); 17 Sep 2001 11:07:57 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 4229 Received: (qmail 6442 invoked from network); 17 Sep 2001 11:07:56 -0000 To: zsh-users@sunsite.dk Subject: Re: retrieving invocation arguments In-reply-to: "Sweth Chandramouli"'s message of "Mon, 17 Sep 2001 11:02:15 BST." <20010917060215.A16077@astaroth.sweth.net> Date: Mon, 17 Sep 2001 12:07:14 +0100 Message-ID: <19990.1000724834@csr.com> From: Peter Stephenson Sweth Chandramouli wrote: > On Sat, Sep 15, 2001 at 05:34:27PM +0000, Bart Schaefer wrote: > > On Sep 14, 9:42pm, Adam Spiers wrote: > > } > > } What's the best way of retrieving the arguments with which zsh was > > } invoked? > > > > By examining $0, $-, and $*. This is imperfect; $- doesn't tell you > > what options were turned off. > Why can't you just parse the output of setopt? I think > you and I had a thread about how to do that easily a couple of years > ago; it should be in the archives, and it wouldn't be hard to modify. Or use the $options array from zsh/parameter. Here's a function that saves your options to a file; you just source that file to restore the options. (The for-loop uses new 4.1 syntax, it's not too hard to make it backward-compatible.) ## begin saveopts zmodload -e zsh/parameter # guard against ksh array syntax being in force local saveopts # N.B. $saveopts is normal array set -A saveopts ${(kv)options} emulate -L zsh if [[ $# != 1 ]]; then print "Usage: saveopts save_file" >&2 return 1 fi local savefile=$1 shift local key val onlist offlist onlist=() offlist=() for key val in $saveopts; do [[ $key = (interactive|shinstdin|stdin) ]] && continue if [[ $val = on ]]; then onlist=($onlist $key) else offlist=($offlist $key) fi done { print -r setopt ${(pj. \\\n.)${(o)onlist}} print print -r unsetopt ${(opj. \\\n.)${(o)offlist}} } >$savefile ## end saveopts -- Peter Stephenson Software Engineer CSR Ltd., Science Park, Milton Road, Cambridge, CB4 0WH, UK Tel: +44 (0)1223 392070 ********************************************************************** The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer. **********************************************************************