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

Re: Can we have an additional output option for setopt?



On Wed, 18 Jan 2012 22:08:43 +0100
Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
> printf '%s\t%s\n' ${(kv)options}

Here's one way of getting setopt to do that (a bit more neatly).

setopt() {
  if (( $# )); then
    typeset -ga global_setopt_args
    global_setopt_args=("$@")
    trap 'builtin setopt "${(@)global_setopt_args}"' EXIT
  else
    local k
    zmodload -i zsh/parameter

    for k in ${(ok)options}; do
      printf "%-20s\t%s\n" $k ${options[$k]}
    done
  fi
}

It's a little hairy because running setopt as a function is unnatural
owing to the fact that certain options (xtrace in particular) always
have function scope.  Alternatively, just use a separate function.

showoptions() {
  local k
  zmodload -i zsh/parameter

  for k in ${(ok)options}; do
    printf "%-20s\t%s\n" $k ${options[$k]}
  done
}

-- 
Peter Stephenson <pws@xxxxxxx>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom
More information can be found at www.csr.com. Follow CSR on Twitter at http://twitter.com/CSR_PLC and read our blog at www.csr.com/blog



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