From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 622 invoked from network); 8 Jul 2004 09:50:09 -0000 Received: from odin.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.85) by ns1.primenet.com.au with SMTP; 8 Jul 2004 09:50:09 -0000 Received: (qmail 4646 invoked from network); 8 Jul 2004 09:50:34 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 8 Jul 2004 09:50:34 -0000 Received: (qmail 11304 invoked by alias); 8 Jul 2004 09:49:27 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 7670 Received: (qmail 11294 invoked from network); 8 Jul 2004 09:49:27 -0000 Received: from odin.dotsrc.org (HELO a.mx.sunsite.dk) (qmailr@130.225.247.85) by sunsite.dk with SMTP; 8 Jul 2004 09:49:27 -0000 Received: (qmail 3564 invoked from network); 8 Jul 2004 09:50:01 -0000 Received: from lhuumrelay3.lnd.ops.eu.uu.net (62.189.58.19) by a.mx.sunsite.dk with SMTP; 8 Jul 2004 09:49:47 -0000 Received: from MAILSWEEPER01.csr.com (mailhost1.csr.com [62.189.183.235]) by lhuumrelay3.lnd.ops.eu.uu.net (8.11.0/8.11.0) with ESMTP id i689mkv25949 for ; Thu, 8 Jul 2004 09:48:46 GMT Received: from EXCHANGE02.csr.com (unverified [192.168.137.45]) by MAILSWEEPER01.csr.com (Content Technologies SMTPRS 4.3.12) with ESMTP id ; Thu, 8 Jul 2004 10:48:05 +0100 Received: from news01.csr.com ([192.168.143.38]) by EXCHANGE02.csr.com with Microsoft SMTPSVC(5.0.2195.6713); Thu, 8 Jul 2004 10:49:46 +0100 Received: from news01.csr.com (localhost.localdomain [127.0.0.1]) by news01.csr.com (8.12.11/8.12.11) with ESMTP id i689mimU006349; Thu, 8 Jul 2004 10:48:44 +0100 Received: from csr.com (pws@localhost) by news01.csr.com (8.12.11/8.12.11/Submit) with ESMTP id i689mhvK006346; Thu, 8 Jul 2004 10:48:44 +0100 Message-Id: <200407080948.i689mhvK006346@news01.csr.com> X-Authentication-Warning: news01.csr.com: pws owned process doing -bs To: gj@freeshell.org, zsh-users@sunsite.dk Subject: Re: why won't this function work? In-reply-to: "gj@freeshell.org"'s message of "Thu, 08 Jul 2004 02:37:41 -0000." Date: Thu, 08 Jul 2004 10:48:43 +0100 From: Peter Stephenson X-OriginalArrivalTime: 08 Jul 2004 09:49:46.0498 (UTC) FILETIME=[E703D620:01C464D0] X-Spam-Checker-Version: SpamAssassin 2.63 on a.mx.sunsite.dk X-Spam-Level: ** X-Spam-Status: No, hits=2.3 required=6.0 tests=BAYES_70 autolearn=no version=2.63 X-Spam-Hits: 2.3 gj@freeshell.org wrote: > I'm trying to convert a function I wrote in bash to zsh. How can I get this > to work? It's a bit more than you asked for, but here it is rewritten to use some additional zsh features. I've put comments where it's obscure. With the right options, you could get the same function to work in bash and zsh. I haven't bothered to try, it doesn't sound like that's what you were after. selhist () { # The following ensures a consistent environment for the function. emulate -L zsh # $'-style quoting avoids using explicit special characters. # (That works in bash, too.) # Added `local' variable definitions for tidiness. local TAB=$'\t'; (( $# < 1 )) && { echo "Usage: selhist [command]" return 1 }; local -a cmd # Use zsh's hacky but useful split-into-lines syntax. # The (f) means `split input lines on newlines.' # This means we can avoid messing with IFS. (That should work, too.) # Note the padding elements are unnecessary. cmd=(${(f)"$(grep -w $1 $HISTFILE | sort | uniq | pr -tn)"}) # The following version is necessary if you are using zsh's # extended_history option, which puts extra information at # the start of history lines. (It's harmless in other cases # unless you are in the habit of re-executing colon commands.) # cmd=(${(f)"$(sed -e 's/^:[^;]*;//' $HISTFILE | grep -w $1 | # sort | uniq | pr -tn)"}) # Slightly simplified output possible in zsh, which won't # split variables on spaces unless sh_word_split is set. # (It would be simpler to use the pr -tn at this point, then # it doesn't have to be stripped off later.) print -l $cmd | less -F # Note the renumbering here. echo -n "enter number of desired command [1 - $(( ${#cmd[@]} - 1 ))]: " local answer read answer # The eval works, but the following is a little more flexible: # it loads the line into the line editor, so you can edit # further, or just hit return. (It's a little like using the # hist_verify option with !-style history.) print -z "${cmd[$answer]#*$TAB}" # Original version. # eval "${cmd[$answer]#*$TAB}" } -- Peter Stephenson Software Engineer CSR Ltd., Science Park, Milton Road, Cambridge, CB4 0WH, UK Tel: +44 (0)1223 692070 ********************************************************************** This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. This footnote also confirms that this email message has been swept by MIMEsweeper for the presence of computer viruses. www.mimesweeper.com **********************************************************************