* history puzzle @ 2024-06-04 18:00 Ray Andrews 2024-06-04 18:12 ` Mark J. Reed 2024-06-04 18:54 ` Kannan Varadhan 0 siblings, 2 replies; 15+ messages in thread From: Ray Andrews @ 2024-06-04 18:00 UTC (permalink / raw) To: Zsh Users [-- Attachment #1: Type: text/plain, Size: 397 bytes --] Trying to do fancier things with history I'm clearly not understanding something. Doc says '^' is first word in a history entry and '$' is the last. But: % history -m "^" 1 # Shows everything % history -m "^nosuchstring" 1 # Also shows everything % history -m "$" 1 # Shows nothing ... so I'm obviously missing something. [-- Attachment #2: Type: text/html, Size: 773 bytes --] ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: history puzzle 2024-06-04 18:00 history puzzle Ray Andrews @ 2024-06-04 18:12 ` Mark J. Reed 2024-06-04 19:28 ` Lawrence Velázquez 2024-06-04 19:49 ` Ray Andrews 2024-06-04 18:54 ` Kannan Varadhan 1 sibling, 2 replies; 15+ messages in thread From: Mark J. Reed @ 2024-06-04 18:12 UTC (permalink / raw) To: Zsh Users [-- Attachment #1: Type: text/plain, Size: 822 bytes --] What's "history -m"? Doesn't that just look for items in the history containing "-m"? "Word" sounds like you're reading about expansions, as in: !! - most recent command !!:$ - last word of most recent command !!:^ - same as :1, first argument word of most recent command !!:0 - just the command name of most recent command Mark J. Reed <markjreed@gmail.com> On Tue, Jun 4, 2024 at 14:01 Ray Andrews <rayandrews@eastlink.ca> wrote: > Trying to do fancier things with history I'm clearly not understanding > something. Doc says '^' is first word in a history entry and '$' is the > last. But: > > % history -m "^" 1 # Shows everything > % history -m "^nosuchstring" 1 # Also shows everything > % history -m "$" 1 # Shows nothing > > ... so I'm obviously missing something. > > [-- Attachment #2: Type: text/html, Size: 2150 bytes --] ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: history puzzle 2024-06-04 18:12 ` Mark J. Reed @ 2024-06-04 19:28 ` Lawrence Velázquez 2024-06-04 19:52 ` Ray Andrews 2024-06-04 19:49 ` Ray Andrews 1 sibling, 1 reply; 15+ messages in thread From: Lawrence Velázquez @ 2024-06-04 19:28 UTC (permalink / raw) To: zsh-users On Tue, Jun 4, 2024, at 2:12 PM, Mark J. Reed wrote: > What's "history -m"? Doesn't that just look for items in the history > containing "-m"? It's the same as "fc -lm": it lists history events that are within the (explicitly or implicitly) specified range and that match the pattern given as the option-argument to -m. -- vq ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: history puzzle 2024-06-04 19:28 ` Lawrence Velázquez @ 2024-06-04 19:52 ` Ray Andrews 2024-06-04 20:18 ` Lawrence Velázquez 0 siblings, 1 reply; 15+ messages in thread From: Ray Andrews @ 2024-06-04 19:52 UTC (permalink / raw) To: zsh-users On 2024-06-04 12:28, Lawrence Velázquez wrote: > On Tue, Jun 4, 2024, at 2:12 PM, Mark J. Reed wrote: >> What's "history -m"? Doesn't that just look for items in the history >> containing "-m"? > It's the same as "fc -lm": it lists history events that are within > the (explicitly or implicitly) specified range and that match the > pattern given as the option-argument to -m. Well that's a relief to hear. So I'm not crazy. My function works fine. I'm now just trying to figure out this "^" thing. > ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: history puzzle 2024-06-04 19:52 ` Ray Andrews @ 2024-06-04 20:18 ` Lawrence Velázquez 0 siblings, 0 replies; 15+ messages in thread From: Lawrence Velázquez @ 2024-06-04 20:18 UTC (permalink / raw) To: zsh-users On Tue, Jun 4, 2024, at 3:52 PM, Ray Andrews wrote: > Well that's a relief to hear. So I'm not crazy. My function works > fine. I'm now just trying to figure out this "^" thing. Look at the "FILENAME GENERATION" section of zshexpn(1). % history -m "^" 1 # Shows everything % history -m "^nosuchstring" 1 # Also shows everything With EXTENDED_GLOB set, "^" matches anything except the empty string, and "^nosuchstring" matches anything except the string "nosuchstring". % history -m "$" 1 # Shows nothing The character "$" is not special in patterns, so this only matches the string "$". -- vq ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: history puzzle 2024-06-04 18:12 ` Mark J. Reed 2024-06-04 19:28 ` Lawrence Velázquez @ 2024-06-04 19:49 ` Ray Andrews 2024-06-04 20:19 ` Lawrence Velázquez 1 sibling, 1 reply; 15+ messages in thread From: Ray Andrews @ 2024-06-04 19:49 UTC (permalink / raw) To: zsh-users On 2024-06-04 11:12, Mark J. Reed wrote: > What's "history -m"? Doesn't that just look for items in the history > containing "-m"? The Devil! Had that in my function for years, thought it meant 'pattern following'. Nuts, it works: 5 /aWorking/Zsh/Source/Wk 1 % history -rn "grep*" 1 fc: event not found: grep* 5 /aWorking/Zsh/Source/Wk 1 % history -rnm "grep*" 1 grep c52f */idProduct grep c52f grep c349 */idProduct ... ... but I can't find it in the doc :( A few examples would be so helpful. ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: history puzzle 2024-06-04 19:49 ` Ray Andrews @ 2024-06-04 20:19 ` Lawrence Velázquez 2024-06-04 20:37 ` Mark J. Reed 2024-06-04 23:48 ` Ray Andrews 0 siblings, 2 replies; 15+ messages in thread From: Lawrence Velázquez @ 2024-06-04 20:19 UTC (permalink / raw) To: zsh-users On Tue, Jun 4, 2024, at 3:49 PM, Ray Andrews wrote: > On 2024-06-04 11:12, Mark J. Reed wrote: >> What's "history -m"? Doesn't that just look for items in the history >> containing "-m"? > The Devil! Had that in my function for years, thought it meant 'pattern > following'. Nuts, it works: > > 5 /aWorking/Zsh/Source/Wk 1 % history -rn "grep*" 1 > fc: event not found: grep* > > 5 /aWorking/Zsh/Source/Wk 1 % history -rnm "grep*" 1 > grep c52f */idProduct > grep c52f > grep c349 */idProduct > ... > > ... but I can't find it in the doc :( A few examples would be so helpful. See the description of "fc" in zshbuiltins(1). No examples, though. -- vq ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: history puzzle 2024-06-04 20:19 ` Lawrence Velázquez @ 2024-06-04 20:37 ` Mark J. Reed 2024-06-04 23:51 ` Ray Andrews 2024-06-04 23:48 ` Ray Andrews 1 sibling, 1 reply; 15+ messages in thread From: Mark J. Reed @ 2024-06-04 20:37 UTC (permalink / raw) To: Lawrence Velázquez; +Cc: zsh-users [-- Attachment #1: Type: text/plain, Size: 2190 bytes --] What the . . . oh, I had *history* aliased for some reason, to *history -t %FT%T 0*. Convenient when I type it by itself, but too late for *-m* by the end of it; I so rarely use the command that I didn't notice I'd restricted myself that way. Sorry for the added confusion. (I replaced it with a function that only adds those arguments if I didn't supply any already.) I still think from Ray's mention of "words" that he was reading documentation about history expansion rather than pattern-matching. So, OK, *-m* option restricts the list of history entries printed out to those matching the pattern. The argument is a glob pattern of the sort used to match files, not a regular expression. Even if it were a regular expression, though, *^ * and *$* would still match everything, since every string has a beginning and an end. So I'm not clear what your goal was. If you have *extendedglob* turned on, then *^ *is negation; *^foo* matches anything that doesn't match *foo*, so *^* again matches everything. If you don't have *extendedglob* turned on, it's not special at all, and *^* looks for an entry exactly equal to nothing but "*^*". And *$* is not special either way, so that is again looking for an entry consisting of nothing but a single dollar sign, and not surprisingly failing to find one. On Tue, Jun 4, 2024 at 4:21 PM Lawrence Velázquez <larryv@zsh.org> wrote: > On Tue, Jun 4, 2024, at 3:49 PM, Ray Andrews wrote: > > On 2024-06-04 11:12, Mark J. Reed wrote: > >> What's "history -m"? Doesn't that just look for items in the history > >> containing "-m"? > > The Devil! Had that in my function for years, thought it meant 'pattern > > following'. Nuts, it works: > > > > 5 /aWorking/Zsh/Source/Wk 1 % history -rn "grep*" 1 > > fc: event not found: grep* > > > > 5 /aWorking/Zsh/Source/Wk 1 % history -rnm "grep*" 1 > > grep c52f */idProduct > > grep c52f > > grep c349 */idProduct > > ... > > > > ... but I can't find it in the doc :( A few examples would be so > helpful. > > See the description of "fc" in zshbuiltins(1). No examples, though. > > -- > vq > > -- Mark J. Reed <markjreed@gmail.com> [-- Attachment #2: Type: text/html, Size: 3062 bytes --] ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: history puzzle 2024-06-04 20:37 ` Mark J. Reed @ 2024-06-04 23:51 ` Ray Andrews 0 siblings, 0 replies; 15+ messages in thread From: Ray Andrews @ 2024-06-04 23:51 UTC (permalink / raw) To: zsh-users [-- Attachment #1: Type: text/plain, Size: 768 bytes --] On 2024-06-04 13:37, Mark J. Reed wrote: > What the . . . oh, I had *history* aliased for some reason, to > *history -t %FT%T 0*. Convenient when I type it by itself, but too > late for *-m* by the end of it; I so rarely use the command that I > didn't notice I'd restricted myself that way. Sorry for the added > confusion. Lawrence caught it before I went and killed myself. Seriously you haven't lead me astray very often. > > (I replaced it with a function that only adds those arguments if I > didn't supply any already.) > > I still think from Ray's mention of "words" that he was reading > documentation about history expansion rather than pattern-matching. I think that's what's happening. 'history' refers to the 'topic' and not the command. [-- Attachment #2: Type: text/html, Size: 1596 bytes --] ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: history puzzle 2024-06-04 20:19 ` Lawrence Velázquez 2024-06-04 20:37 ` Mark J. Reed @ 2024-06-04 23:48 ` Ray Andrews 2024-06-05 0:33 ` Lawrence Velázquez 1 sibling, 1 reply; 15+ messages in thread From: Ray Andrews @ 2024-06-04 23:48 UTC (permalink / raw) To: zsh-users [-- Attachment #1: Type: text/plain, Size: 483 bytes --] On 2024-06-04 13:19, Lawrence Velázquez wrote: > See the description of "fc" in zshbuiltins(1). No examples, though. I was reading 'info zsh history' ... definitely says '^' is first word and '$' is last word, so I seem to have the wrong doc. Come to think of it, I couldn't make sense of very much of it, so maybe that's the reason. So the pattern matching follows globbing rules? Ok, that makes sense. Now that I know where to look it should go more smoothly. Tx. [-- Attachment #2: Type: text/html, Size: 1104 bytes --] ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: history puzzle 2024-06-04 23:48 ` Ray Andrews @ 2024-06-05 0:33 ` Lawrence Velázquez 2024-06-05 2:00 ` Ray Andrews 0 siblings, 1 reply; 15+ messages in thread From: Lawrence Velázquez @ 2024-06-05 0:33 UTC (permalink / raw) To: zsh-users On Tue, Jun 4, 2024, at 7:48 PM, Ray Andrews wrote: > On 2024-06-04 13:19, Lawrence Velázquez wrote: >> See the description of "fc" in zshbuiltins(1). No examples, though. > I was reading 'info zsh history' That shows the "History Expansion" section of the manual, which does not mention the "history" builtin at all. -- vq ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: history puzzle 2024-06-05 0:33 ` Lawrence Velázquez @ 2024-06-05 2:00 ` Ray Andrews 2024-06-05 15:53 ` Mark J. Reed 0 siblings, 1 reply; 15+ messages in thread From: Ray Andrews @ 2024-06-05 2:00 UTC (permalink / raw) To: zsh-users [-- Attachment #1: Type: text/plain, Size: 476 bytes --] On 2024-06-04 17:33, Lawrence Velázquez wrote: > I was reading 'info zsh history' > That shows the "History Expansion" section of the manual, which > does not mention the "history" builtin at all. > Ok, at least that's clear. I should be using 'info zshbuiltins'. 'History Expansion' ... I'm taking that to be what the history command does so ... actually now that I look closely, it's obviously the wrong place. And 'run-help history' goes somewhere else entirely. [-- Attachment #2: Type: text/html, Size: 933 bytes --] ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: history puzzle 2024-06-05 2:00 ` Ray Andrews @ 2024-06-05 15:53 ` Mark J. Reed 2024-06-05 16:13 ` Ray Andrews 0 siblings, 1 reply; 15+ messages in thread From: Mark J. Reed @ 2024-06-05 15:53 UTC (permalink / raw) To: zsh-users [-- Attachment #1: Type: text/plain, Size: 1833 bytes --] On Tue, Jun 4, 2024 at 10:01 PM Ray Andrews <rayandrews@eastlink.ca> wrote: > > > On 2024-06-04 17:33, Lawrence Velázquez wrote: > > I was reading 'info zsh history' > > That shows the "History Expansion" section of the manual, which > does not mention the "history" builtin at all. > > > Ok, at least that's clear. I should be using 'info zshbuiltins'. > 'History Expansion' ... I'm taking that to be what the history command does > so ... actually now that I look closely, it's obviously the wrong place. > And 'run-help history' goes somewhere else entirely. > The term "history expansion" refers to the expansion of references into the command history. Those start with *!, *for example: *zsh% vi path/to/some/file* *zsh% gcc !$ # compile the file I just edited* In general, the *!* is followed by a selector that determines which item from the history you want to copy from. This can be an item number (which matches the one shown by *history*/*fc -l*), another *! *(which means the most recent command), or a prefix string (which refers to the most recent command starting with that prefix, e.g. *!ls* to refer to the most recent *ls* command). The selector can be followed by modifiers to restrict the expansion to just part of the command: *:0 *for the command name, *:** for the arguments without the command name, *:$* for just the last argument, etc. The *!!:$* expression (last word of the last command) is so common that it got its own shortcut, the *!$* I used above. History expansion is purely an interactive command-line feature; it doesn't work in scripts. If you need to access the history programmatically, use the *fc* command (or *history*, which is equivalent to *fc -l*). Anyway, that's what you were reading about. :) -- Mark J. Reed <markjreed@gmail.com> [-- Attachment #2: Type: text/html, Size: 3256 bytes --] ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: history puzzle 2024-06-05 15:53 ` Mark J. Reed @ 2024-06-05 16:13 ` Ray Andrews 0 siblings, 0 replies; 15+ messages in thread From: Ray Andrews @ 2024-06-05 16:13 UTC (permalink / raw) To: zsh-users [-- Attachment #1: Type: text/plain, Size: 665 bytes --] On 2024-06-05 08:53, Mark J. Reed wrote: > > History expansion is purely an interactive command-line feature; it > doesn't work in scripts. If you need to access the history > programmatically, use the *fc* command (or *history*, which is > equivalent to *fc -l*). > > Anyway, that's what you were reading about. :) I wish I could kill the whole thread, it was a misunderstanding from the getgo. Not the first time I've ended up barking up entirely the wrong tree. And with hindsight it is obvious I wasn't looking at a command -- but I'm so used to being baffled by the manual that I took it as normal ;-) > -- > Mark J. Reed <markjreed@gmail.com> [-- Attachment #2: Type: text/html, Size: 2130 bytes --] ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: history puzzle 2024-06-04 18:00 history puzzle Ray Andrews 2024-06-04 18:12 ` Mark J. Reed @ 2024-06-04 18:54 ` Kannan Varadhan 1 sibling, 0 replies; 15+ messages in thread From: Kannan Varadhan @ 2024-06-04 18:54 UTC (permalink / raw) To: Ray Andrews, Zsh Users [-- Attachment #1: Type: text/plain, Size: 662 bytes --] Aren't you basically asking zsh to show you empty strings so nothing comes back? -- Reply to: Kannan@ieee.org ________________________________ From: Ray Andrews <rayandrews@eastlink.ca> Sent: Tuesday, June 4, 2024 11:00 AM To: Zsh Users Subject: history puzzle Trying to do fancier things with history I'm clearly not understanding something. Doc says '^' is first word in a history entry and '$' is the last. But: % history -m "^" 1 # Shows everything % history -m "^nosuchstring" 1 # Also shows everything % history -m "$" 1 # Shows nothing ... so I'm obviously missing something. [-- Attachment #2: Type: text/html, Size: 1971 bytes --] ^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2024-06-05 16:13 UTC | newest] Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2024-06-04 18:00 history puzzle Ray Andrews 2024-06-04 18:12 ` Mark J. Reed 2024-06-04 19:28 ` Lawrence Velázquez 2024-06-04 19:52 ` Ray Andrews 2024-06-04 20:18 ` Lawrence Velázquez 2024-06-04 19:49 ` Ray Andrews 2024-06-04 20:19 ` Lawrence Velázquez 2024-06-04 20:37 ` Mark J. Reed 2024-06-04 23:51 ` Ray Andrews 2024-06-04 23:48 ` Ray Andrews 2024-06-05 0:33 ` Lawrence Velázquez 2024-06-05 2:00 ` Ray Andrews 2024-06-05 15:53 ` Mark J. Reed 2024-06-05 16:13 ` Ray Andrews 2024-06-04 18:54 ` Kannan Varadhan
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).