Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: retrieving invocation arguments
- X-seq: zsh-users 4229
- From: Peter Stephenson <pws@xxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: retrieving invocation arguments
- Date: Mon, 17 Sep 2001 12:07:14 +0100
- In-reply-to: "Sweth Chandramouli"'s message of "Mon, 17 Sep 2001 11:02:15 BST." <20010917060215.A16077@xxxxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
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@xxxxxxx> 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.
**********************************************************************
Messages sorted by:
Reverse Date,
Date,
Thread,
Author