]> git.lizzy.rs Git - linenoise.git/commitdiff
Do not add duplicates lines to history
authordvir volk <dvir@doit9.com>
Wed, 28 Sep 2011 21:07:01 +0000 (00:07 +0300)
committerSteve Bennett <steveb@workware.net.au>
Thu, 29 Sep 2011 03:24:58 +0000 (13:24 +1000)
If the previous line is identical to the new line

linenoise.c

index 8e795b3f9ad98f343237959f4ec1f08689999622..8615508aa759382d8c7f76e0607992090ebe3b4d 100644 (file)
@@ -1261,6 +1261,12 @@ int linenoiseHistoryAdd(const char *line) {
         if (history == NULL) return 0;
         memset(history,0,(sizeof(char*)*history_max_len));
     }
+
+    /* do not insert duplicate lines into history */
+    if (history_len > 0 && strcmp(line, history[history_len - 1]) == 0) {
+        return 0;
+    }
+
     linecopy = strdup(line);
     if (!linecopy) return 0;
     if (history_len == history_max_len) {