From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2292 invoked from network); 12 Jul 2004 21:56:14 -0000 Received: from odin.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.85) by ns1.primenet.com.au with SMTP; 12 Jul 2004 21:56:14 -0000 Received: (qmail 5841 invoked from network); 12 Jul 2004 21:59:31 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 12 Jul 2004 21:59:32 -0000 Received: (qmail 18258 invoked by alias); 12 Jul 2004 21:55:31 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 7690 Received: (qmail 18248 invoked from network); 12 Jul 2004 21:55:30 -0000 Received: from odin.dotsrc.org (HELO a.mx.sunsite.dk) (qmailr@130.225.247.85) by sunsite.dk with SMTP; 12 Jul 2004 21:55:30 -0000 Received: (qmail 4894 invoked from network); 12 Jul 2004 21:59:03 -0000 Received: from ol.freeshell.org (HELO sdf.lonestar.org) (@192.94.73.20) by a.mx.sunsite.dk with SMTP; 12 Jul 2004 21:58:50 -0000 Received: from sdf.lonestar.org (IDENT:gj@ukato.freeshell.org [192.94.73.7]) by sdf.lonestar.org (8.12.10/8.12.10) with ESMTP id i6CLtAl2020879; Mon, 12 Jul 2004 21:55:10 GMT Received: (from gj@localhost) by sdf.lonestar.org (8.12.10/8.12.8/Submit) id i6CLt9cg004114; Mon, 12 Jul 2004 21:55:09 GMT Date: Mon, 12 Jul 2004 21:55:09 +0000 From: gj@freeshell.org To: Peter Stephenson Cc: zsh-users@sunsite.dk Subject: Re: why won't this function work? Message-ID: <20040712215509.GA15737@SDF.LONESTAR.ORG> References: <200407080948.i689mhvK006346@news01.csr.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200407080948.i689mhvK006346@news01.csr.com> User-Agent: Mutt/1.4.2.1i X-Spam-Checker-Version: SpamAssassin 2.63 on a.mx.sunsite.dk X-Spam-Level: X-Spam-Status: No, hits=0.2 required=6.0 tests=NO_REAL_NAME autolearn=no version=2.63 X-Spam-Hits: 0.2 On Thu, Jul 08, 2004 at 10:48:43AM +0100, Peter Stephenson wrote: > gj@freeshell.org wrote: > > I'm trying to convert a function I wrote in bash to zsh. How can I get > > this to work? > > > 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}" Wow, that is a cool option! > # Original version. > # eval "${cmd[$answer]#*$TAB}" > } This subroutine doesn't work when I try it on 4.0.7/sparc64 and 4.0.7/alpha. It just hangs there like it's waiting for input, though it's not. Thanks, G.