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

Re: retrieving invocation arguments

On Sep 17, 12:07pm, Peter Stephenson wrote:
} Subject: Re: retrieving invocation arguments
} 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.)

It's also not hard to do away with it entirely!

  ## begin saveopts
  emulate -L zsh	# This takes care of ksharrays et al.

  # I'm not sure what PWS was doing with zmodload -e ...
  zmodload -i zsh/parameter || return $?

  if [[ $# != 1 ]]; then
    print "Usage: saveopts save_file" >&2
    return 1

  local x='(interactive|shinstdin|stdin)'
    print -r setopt ${(pj. \\\n .)${(ok)options[(R)on]:#$~x}}
    print -r unsetopt ${(pj. \\\n .)${(ok)options[(R)off]:#$~x}}
  } > $1
  ## end saveopts

Of course none of this answers the original question, because by the time
the user gets to execute any shell code the options may have been changed
by /etc/zshenv.

Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   

Messages sorted by: Reverse Date, Date, Thread, Author