Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: why won't this function work?
- X-seq: zsh-users 7690
- From: gj@xxxxxxxxxxxxx
- To: Peter Stephenson <pws@xxxxxxx>
- Subject: Re: why won't this function work?
- Date: Mon, 12 Jul 2004 21:55:09 +0000
- Cc: zsh-users@xxxxxxxxxx
- In-reply-to: <200407080948.i689mhvK006346@xxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <Pine.NEB.4.60.0407080235030.11144@xxxxxxxxxxxxxxxx> <200407080948.i689mhvK006346@xxxxxxxxxxxxxx>
On Thu, Jul 08, 2004 at 10:48:43AM +0100, Peter Stephenson wrote:
> gj@xxxxxxxxxxxxx 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.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author