From 7ccdc98a5f7d3dfc4a1fe82efa08c206008c81e1 Mon Sep 17 00:00:00 2001 From: Michael Yang Date: Sat, 21 Dec 2024 00:08:12 -0800 Subject: [PATCH] fix: only add to history of different if the last item in history is the same as the one being added, skip it. this reduces the number of history entries. the behaviour is similar to how most shells maintain history --- readline/history.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/readline/history.go b/readline/history.go index bf3cafe25..b3661e29b 100644 --- a/readline/history.go +++ b/readline/history.go @@ -81,11 +81,13 @@ func (h *History) Init() error { } func (h *History) Add(s string) { - h.Buf.Add(s) - h.Compact() - h.Pos = h.Size() - if h.Autosave { - _ = h.Save() + if latest, _ := h.Buf.Get(h.Size() - 1); latest != s { + h.Buf.Add(s) + h.Compact() + h.Pos = h.Size() + if h.Autosave { + _ = h.Save() + } } }