From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9626 invoked from network); 29 Jan 2003 16:19:11 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 29 Jan 2003 16:19:11 -0000 Received: (qmail 8768 invoked by alias); 29 Jan 2003 16:18:45 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 5842 Received: (qmail 8761 invoked from network); 29 Jan 2003 16:18:45 -0000 Received: from localhost (HELO sunsite.dk) (127.0.0.1) by localhost with SMTP; 29 Jan 2003 16:18:45 -0000 X-MessageWall-Score: 0 (sunsite.dk) Received: from [195.64.83.12] by sunsite.dk (MessageWall 1.0.8) with SMTP; 29 Jan 2003 16:18:45 -0000 Received: by timix.globnix.org with local id 18duvD-0004WH-00; Wed, 29 Jan 2003 16:18:43 +0000 Date: Wed, 29 Jan 2003 16:18:43 +0000 From: Phil Pennock To: Clifford Caoile Cc: zsh-users@sunsite.dk Subject: Re: a calculator for zsh-4.x Message-ID: <20030129161843.GA20920@globnix.org> Mail-Followup-To: Clifford Caoile , zsh-users@sunsite.dk References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Organisation: Demon Internet Netherlands On 2003-01-30 at 01:03 +0900, Clifford Caoile wrote: > I don't know about you, but I reach for zsh when I want to calculate > addition in hexadecimal I also tend to do this; messing around with graphical calculators is a pain. > # -----------------------------------------------------------------begin > # calculator - paste me into your .zshrc > # ---------------------------------------------------------------------- > > # Here are some quick calculators that output in integer > # hexadecimal, decimal, and binary. > zcalc () { print $(( ans = ${1:-ans} )) } > zcalch () { print $(( [#16] ans = ${1:-ans} )) } > zcalcd () { print $(( [#10] ans = ${1:-ans} )) } > zcalco () { print $(( [#8] ans = ${1:-ans} )) } > zcalcb () { print $(( [#2] ans = ${1:-ans} )) } > > # A key binding that will allow you to quickly get into zcalc > bindkey -s '\C-xd' "zcalc \'" > > # this last one lets you calculate the ascii value of a single character > zcalcasc () { print $(( [#16] ans = ##${1:-ans} )) } > # -------------------------------------------------------------------end I like it. :^) But with one modification: for the first five functions, replace ${1:-ans} with ${@:-ans} so that the quotes are unnecessary unless you're using characters interpreted by the shell. > Call for advice: > Actually, I'm most interested in enhancing the bindkey definition. Placing > just one quotation mark on the command line seems to be sloppy. I just bypass the need for the bindkey for most of the things I'd use these functions for. Thanks,