Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: retrieving invocation arguments

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

## 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

local savefile=$1

local key val onlist offlist

for key val in $saveopts; do
  [[ $key = (interactive|shinstdin|stdin) ]] && continue
  if [[ $val = on ]]; then
    onlist=($onlist $key)
    offlist=($offlist $key)

  print -r setopt ${(pj. \\\n.)${(o)onlist}}
  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 
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