From: gj@freeshell.org
To: Peter Stephenson <pws@csr.com>
Cc: zsh-users@sunsite.dk
Subject: Re: why won't this function work?
Date: Mon, 12 Jul 2004 21:55:09 +0000 [thread overview]
Message-ID: <20040712215509.GA15737@SDF.LONESTAR.ORG> (raw)
In-Reply-To: <200407080948.i689mhvK006346@news01.csr.com>
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.
prev parent reply other threads:[~2004-07-12 21:56 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-07-08 2:37 gj
2004-07-08 6:49 ` Bart Schaefer
2004-07-08 9:48 ` Peter Stephenson
2004-07-12 21:55 ` gj [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20040712215509.GA15737@SDF.LONESTAR.ORG \
--to=gj@freeshell.org \
--cc=pws@csr.com \
--cc=zsh-users@sunsite.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).