Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: subsitutions and beginning of lines.



On 10/13/2015 05:23 PM, Bart Schaefer wrote:
What defines a "hit" here?  Your "history" command isn't "searching"
AT ALL.  Rather it's your series of "grep" commands that are doing
the searching.  There's no way an argument to the "history" command
can tell it how many times "grep" of its output is going to succeed.
Yes, how silly of me. history by itself knows nothing of my grepping. Duhhhh.
So it sounds like what you really want is

     eval history -r -n -$HISTSIZE $sstring | head $nnumber

That is, dump the entire history, grep it, and then show the most
recent few events that match the greps.
Sure, but I was hoping for something a little more delicate.
The -m switch does do some internal finding, so maybe that's the
starting point. Couldn't history count it's matches when the '-m' is used?

    history -M$nnumber "*$sstring"*" ... or something.

Never mind tho.  Working from your example above I come up with:

$ history -n -m "*$sstring*" 1 | tail -n $nnumber | grep --color=auto "$sstring"

And it's very satisfactory.  She burns through the entire history so fast
that there's nothing to complain about.   Thanks Bart.




Messages sorted by: Reverse Date, Date, Thread, Author