From: Peter Stephenson <pws@csr.com>
To: zsh-users@sunsite.dk
Subject: Re: retrieving invocation arguments
Date: Mon, 17 Sep 2001 12:07:14 +0100 [thread overview]
Message-ID: <19990.1000724834@csr.com> (raw)
In-Reply-To: "Sweth Chandramouli"'s message of "Mon, 17 Sep 2001 11:02:15 BST." <20010917060215.A16077@astaroth.sweth.net>
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 <pws@csr.com> 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.
**********************************************************************
next prev parent reply other threads:[~2001-09-17 11:08 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-09-14 20:42 Adam Spiers
2001-09-15 17:34 ` Bart Schaefer
2001-09-17 10:02 ` Sweth Chandramouli
2001-09-17 11:07 ` Peter Stephenson [this message]
2001-09-17 15:17 ` Bart Schaefer
2001-09-17 15:38 ` Peter Stephenson
2001-09-17 16:06 ` Bart Schaefer
2001-09-17 20:59 ` Adam Spiers
2001-09-17 20:25 ` Sweth Chandramouli
2001-09-18 10:53 ` Adam Spiers
2001-09-17 10:23 ` Adam Spiers
2001-09-17 16:13 ` Bart Schaefer
2001-09-18 11:39 ` Adam Spiers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=19990.1000724834@csr.com \
--to=pws@csr.com \
--cc=zsh-users@sunsite.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).