Pārlūkot izejas kodu

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
Michael Yang 4 mēneši atpakaļ
vecāks
revīzija
7ccdc98a5f
1 mainītis faili ar 7 papildinājumiem un 5 dzēšanām
  1. 7 5
      readline/history.go

+ 7 - 5
readline/history.go

@@ -81,11 +81,13 @@ func (h *History) Init() error {
 }
 }
 
 
 func (h *History) Add(s string) {
 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()
+		}
 	}
 	}
 }
 }