From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26829 invoked by alias); 19 Jan 2012 10:51:07 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 16736 Received: (qmail 4202 invoked from network); 19 Jan 2012 10:51:04 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS autolearn=ham version=3.3.2 Received-SPF: none (ns1.primenet.com.au: domain at csr.com does not designate permitted sender hosts) Date: Thu, 19 Jan 2012 10:04:12 +0000 From: Peter Stephenson To: "zsh-users@zsh.org" Subject: Re: Can we have an additional output option for setopt? Message-ID: <20120119100412.24fd288e@pwslap01u.europe.root.pri> In-Reply-To: References: Organization: Cambridge Silicon Radio X-Mailer: Claws Mail 3.7.9 (GTK+ 2.22.0; i386-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.101.10.170] X-Scanned-By: MailControl 7.6.5 (www.mailcontrol.com) on 10.68.0.135 On Wed, 18 Jan 2012 22:08:43 +0100 Mikael Magnusson 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 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