zsh-users
 help / color / mirror / code / Atom feed
* Using history / fc for case-insensitive pattern matching
@ 2022-02-21 17:43 Zach Riggle
  2022-02-21 21:01 ` Mikael Magnusson
  0 siblings, 1 reply; 8+ messages in thread
From: Zach Riggle @ 2022-02-21 17:43 UTC (permalink / raw)
  To: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 724 bytes --]

I've written a neat little tool that wraps "fc" / "history" to make
everything look neat and easily documentable for later reference /
incident response.

    $ command echo 'Hello, zsh-users!'
    Hello, zsh-users!

    $ hgrep zsh-u
    # [2021-12-18 06:13]
    git clone https://github.com/zsh-users/zsh.git

    # [2022-02-21 11:39]
    command echo 'Hello, zsh-users!'

The down-side of this is that it appears "fc ... -m expression" is
case-sensitive.  I expect that Zsh has excellent documentation on the
patterns and how to make them case-insensitive but I haven't managed
to find it yet.  Most of what I've found seems to correspond to file
globbing, which isn't what I'm trying to do here.

Any tips?

Zach Riggle

[-- Attachment #2: image.png --]
[-- Type: image/png, Size: 36950 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Using history / fc for case-insensitive pattern matching
  2022-02-21 17:43 Using history / fc for case-insensitive pattern matching Zach Riggle
@ 2022-02-21 21:01 ` Mikael Magnusson
  2022-02-22  9:09   ` zzapper
  0 siblings, 1 reply; 8+ messages in thread
From: Mikael Magnusson @ 2022-02-21 21:01 UTC (permalink / raw)
  To: Zach Riggle; +Cc: Zsh Users

On 2/21/22, Zach Riggle <zachriggle@gmail.com> wrote:
> I've written a neat little tool that wraps "fc" / "history" to make
> everything look neat and easily documentable for later reference /
> incident response.
>
>     $ command echo 'Hello, zsh-users!'
>     Hello, zsh-users!
>
>     $ hgrep zsh-u
>     # [2021-12-18 06:13]
>     git clone https://github.com/zsh-users/zsh.git
>
>     # [2022-02-21 11:39]
>     command echo 'Hello, zsh-users!'
>
> The down-side of this is that it appears "fc ... -m expression" is
> case-sensitive.  I expect that Zsh has excellent documentation on the
> patterns and how to make them case-insensitive but I haven't managed
> to find it yet.  Most of what I've found seems to correspond to file
> globbing, which isn't what I'm trying to do here.

You can use (#i) to make a pattern case insensitive, eg
fc -m '(#i)*zsh-u*'

you may need to setopt extendedglob first.

-- 
Mikael Magnusson


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Using history / fc for case-insensitive pattern matching
  2022-02-21 21:01 ` Mikael Magnusson
@ 2022-02-22  9:09   ` zzapper
  2022-02-22  9:27     ` Peter Stephenson
  0 siblings, 1 reply; 8+ messages in thread
From: zzapper @ 2022-02-22  9:09 UTC (permalink / raw)
  To: zsh-users


On 21/02/2022 21:01, Mikael Magnusson wrote:
> On 2/21/22, Zach Riggle <zachriggle@gmail.com> wrote:
>> I've written a neat little tool that wraps "fc" / "history" to make
>> everything look neat and easily documentable for later reference /
>> incident response.
>>
> You can use (#i) to make a pattern case insensitive, eg
> fc -m '(#i)*zsh-u*'
>
> you may need to setopt extendedglob first.
>
Thanks Mikael for resolving this

(i needed the -nl)

fc -nl -m '(#i)*Mortg*'

but there's something clunky with the fc -m match .. I can't get to 
match all of my history?

and i fing it simpler to

alias hg='fc -l 1 | grep -i '

zzapper



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Using history / fc for case-insensitive pattern matching
  2022-02-22  9:09   ` zzapper
@ 2022-02-22  9:27     ` Peter Stephenson
  2022-02-22  9:39       ` zzapper
  0 siblings, 1 reply; 8+ messages in thread
From: Peter Stephenson @ 2022-02-22  9:27 UTC (permalink / raw)
  To: zsh-users


> On 22 February 2022 at 09:09 zzapper <zsh@rayninfo.co.uk> wrote:
> On 21/02/2022 21:01, Mikael Magnusson wrote:
> > On 2/21/22, Zach Riggle <zachriggle@gmail.com> wrote:
> >> I've written a neat little tool that wraps "fc" / "history" to make
> >> everything look neat and easily documentable for later reference /
> >> incident response.
> >>
> > You can use (#i) to make a pattern case insensitive, eg
> > fc -m '(#i)*zsh-u*'
> >
> > you may need to setopt extendedglob first.
> >
> Thanks Mikael for resolving this
> 
> (i needed the -nl)
> 
> fc -nl -m '(#i)*Mortg*'
> 
> but there's something clunky with the fc -m match .. I can't get to 
> match all of my history?

Try sticking a "1" at the end of the line to get the whole history.
It still does the match, but it now starts searching from the beginning.

pws


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Using history / fc for case-insensitive pattern matching
  2022-02-22  9:27     ` Peter Stephenson
@ 2022-02-22  9:39       ` zzapper
  2022-02-22  9:47         ` zzapper
  0 siblings, 1 reply; 8+ messages in thread
From: zzapper @ 2022-02-22  9:39 UTC (permalink / raw)
  To: zsh-users


On 22/02/2022 09:27, Peter Stephenson wrote:
>> On 22 February 2022 at 09:09 zzapper <zsh@rayninfo.co.uk> wrote:
>> On 21/02/2022 21:01, Mikael Magnusson wrote:
>>
>> Thanks Mikael for resolving this
>>
>> (i needed the -nl)
>>
>> fc -nl -m '(#i)*Mortg*'
>>
>> but there's something clunky with the fc -m match .. I can't get to
>> match all of my history?
> Try sticking a "1" at the end of the line to get the whole history.
> It still does the match, but it now starts searching from the beginning.
>
> pws


# pws: yes thanks the following works

fc -l -m '(#i)*Mortg*' 1


(should this be documented?)

zzapper



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Using history / fc for case-insensitive pattern matching
  2022-02-22  9:39       ` zzapper
@ 2022-02-22  9:47         ` zzapper
  2022-02-22 10:18           ` Peter Stephenson
  0 siblings, 1 reply; 8+ messages in thread
From: zzapper @ 2022-02-22  9:47 UTC (permalink / raw)
  To: zsh-users

# pws: yes thanks the following works
>
> fc -l -m '(#i)*Mortg*' 1
>
>
> (should this be documented?)
>
> zzapper
>
>
To answer my own question: with fc any number range eg first last 
should/must be the last


Best regards

David Rayner



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Using history / fc for case-insensitive pattern matching
  2022-02-22  9:47         ` zzapper
@ 2022-02-22 10:18           ` Peter Stephenson
  2022-02-22 13:07             ` zzapper
  0 siblings, 1 reply; 8+ messages in thread
From: Peter Stephenson @ 2022-02-22 10:18 UTC (permalink / raw)
  To: zzapper, zsh-users

> On 22 February 2022 at 09:47 zzapper <zsh@rayninfo.co.uk> wrote:
> # pws: yes thanks the following works
> >
> > fc -l -m '(#i)*Mortg*' 1
> >
> >
> > (should this be documented?)
> >
> > zzapper
> >
> >
> To answer my own question: with fc any number range eg first last 
> should/must be the last

Would this be a little clearer?  History (pun intended) shows that
making the docs more verbose doesn't mean people necessarily find
them clearer, but I think they are particularly terse at this point.

pws

diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo
index c7de50f..dbb787f 100644
--- a/Doc/Zsh/builtins.yo
+++ b/Doc/Zsh/builtins.yo
@@ -756,15 +756,16 @@ specifies the most recent event beginning with the given string.  All
 substitutions var(old)tt(=)var(new), if any, are then performed on the
 text of the events.
 
-In addition to the number range,
+The range of events selected by numbers can be narrowed further by the
+following flags.
 startsitem()
 sitem(tt(-I))(restricts to only internal events (not from tt($HISTFILE)))
 sitem(tt(-L))(restricts to only local events (not from other shells, see
 tt(SHARE_HISTORY) in ifzman(zmanref(zshoptions))\
 ifnzman(noderef(Description of Options)) -- note that tt($HISTFILE) is
 considered local when read at startup))
-sitem(tt(-m))(takes the first argument as a pattern (should be quoted) and
-only the history events matching this pattern are considered)
+sitem(tt(-m))(takes the first argument as a pattern (which should be
+quoted) and only the history events matching this pattern are considered)
 endsitem()
 
 If var(first) is not specified, it will be set to -1 (the most recent


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Using history / fc for case-insensitive pattern matching
  2022-02-22 10:18           ` Peter Stephenson
@ 2022-02-22 13:07             ` zzapper
  0 siblings, 0 replies; 8+ messages in thread
From: zzapper @ 2022-02-22 13:07 UTC (permalink / raw)
  To: Peter Stephenson, zsh-users


On 22/02/2022 10:18, Peter Stephenson wrote:
>> To answer my own question: with fc any number range eg first last
>> should/must be the last
> Would this be a little clearer?  History (pun intended) shows that
> making the docs more verbose doesn't mean people necessarily find
> them clearer, but I think they are particularly terse at this point.
>
> pws

Peter you made me laugh out loud when you used the word 'terse'

I often find I understand documentation AFTER I have actually found out 
how to do something LOL (especially assembling flat-pack furniture).

But as you say there is trade-off between verbosity which people may not 
read and simplicity.

In this case however had I really invested in understanding the existing 
fc man page I would spared myself considerable grief.

Isn't there an adage something like '6 hours of coding and testing saves 
1 hour of studying the documentation'?

zzapper



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-02-22 13:08 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-21 17:43 Using history / fc for case-insensitive pattern matching Zach Riggle
2022-02-21 21:01 ` Mikael Magnusson
2022-02-22  9:09   ` zzapper
2022-02-22  9:27     ` Peter Stephenson
2022-02-22  9:39       ` zzapper
2022-02-22  9:47         ` zzapper
2022-02-22 10:18           ` Peter Stephenson
2022-02-22 13:07             ` zzapper

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).