From: Jun T <takimoto-j@kba.biglobe.ne.jp>
To: zsh-workers@zsh.org
Subject: Re: HIST_IGNORE_DUPS also ignores command lines that differ by a space between quotes
Date: Thu, 21 Mar 2024 14:22:46 +0900 [thread overview]
Message-ID: <BD4BCD20-11DD-449A-97D1-995606597DCA@kba.biglobe.ne.jp> (raw)
In-Reply-To: <CAH+w=7YdYNUOaAZimuc02DvumHwVJdWYEATocc-ku95-DNAZig@mail.gmail.com>
I think HIST_IGNORE_DUPS would work as expected even without
HIST_REDUCCE_BLANKS if we use the information in chwords and
hist_ring->words, as in the patch below, for example.
we can't simply replace histstrcmp() with the one that uses
the words[] array in struct histent. But I think Bart's patch
is enough for HIST_IGNORE_ALL_DUPS and history searching
(and recommend users to set HIST_REDUCCE_BLANKS).
diff --git a/Src/hist.c b/Src/hist.c
index 1a00c30ed..3a52ee038 100644
--- a/Src/hist.c
+++ b/Src/hist.c
@@ -1467,6 +1467,36 @@ should_ignore_line(Eprog prog)
return 0;
}
+/*
+ * compare the history entry in {chline,chwords} with the previous
+ * one in hist_ring->{node.nam,words}. Returns 0 if the two are equal
+ * (except for insignificant spaces), nonzero otherwise.
+ */
+
+/**/
+static int
+hist_compare(void)
+{
+ int i;
+
+ if (isset(HISTREDUCEBLANKS))
+ return strcmp(chline, hist_ring->node.nam);
+ if (chwordpos/2 != hist_ring->nwords)
+ return 1;
+ for (i = 0; i < chwordpos; i += 2) {
+ const char *p = &chline[chwords[i]];
+ const char *q = &hist_ring->node.nam[hist_ring->words[i]];
+ int n = chwords[i+1] - chwords[i], j;
+
+ if (n != hist_ring->words[i+1] - hist_ring->words[i])
+ return 1;
+ for (j=0; j < n; ++j)
+ if (p[j] != q[j])
+ return 1;
+ }
+ return 0;
+}
+
/* say we're done using the history mechanism */
/**/
@@ -1600,7 +1630,7 @@ hend(Eprog prog)
else
newflags = 0;
if ((isset(HISTIGNOREDUPS) || isset(HISTIGNOREALLDUPS)) && save > 0
- && hist_ring && histstrcmp(chline, hist_ring->node.nam) == 0) {
+ && hist_ring && hist_compare() == 0) {
/* This history entry compares the same as the previous.
* In case minor changes were made, we overwrite the
* previous one with the current one. This also gets the
next prev parent reply other threads:[~2024-03-21 5:23 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-13 12:38 Vincent Lefevre
2024-03-14 5:13 ` Bart Schaefer
2024-03-15 12:53 ` Vincent Lefevre
2024-03-16 16:00 ` Bart Schaefer
2024-03-19 10:57 ` Vincent Lefevre
2024-03-19 11:08 ` Mikael Magnusson
2024-03-19 12:34 ` Vincent Lefevre
2024-03-20 17:46 ` Bart Schaefer
2024-03-20 17:48 ` Bart Schaefer
2024-03-20 23:48 ` Vincent Lefevre
2024-03-21 5:22 ` Jun T [this message]
2024-03-21 5:36 ` Bart Schaefer
2024-03-21 9:41 ` Jun T
2024-03-21 10:21 ` Vincent Lefevre
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=BD4BCD20-11DD-449A-97D1-995606597DCA@kba.biglobe.ne.jp \
--to=takimoto-j@kba.biglobe.ne.jp \
--cc=zsh-workers@zsh.org \
/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).