From 3d879bd798cfdcf9d79827b5d0624437fc6aac30 Mon Sep 17 00:00:00 2001
From: dllud <dllud@riseup.net>
Date: Fri, 19 May 2023 16:41:29 +0100
Subject: [PATCH] history-substring-search: add fuzzy and unique

---
 modules/history-substring-search/README.md | 18 ++++++++++++++++++
 modules/history-substring-search/init.zsh  |  8 ++++++++
 runcoms/zpreztorc                          |  6 ++++++
 3 files changed, 32 insertions(+)

diff --git a/modules/history-substring-search/README.md b/modules/history-substring-search/README.md
index 3a109c55..42919e0c 100644
--- a/modules/history-substring-search/README.md
+++ b/modules/history-substring-search/README.md
@@ -65,6 +65,24 @@ _`${ZDOTDIR:-$HOME}/.zpreztorc`_:
 zstyle ':prezto:module:history-substring-search' globbing-flags ''
 ```
 
+### Fuzzy search
+
+To enable fuzzy search add the following line to
+`${ZDOTDIR:-$HOME}/.zpreztorc`_:
+
+```sh
+zstyle ':prezto:module:history-substring-search' fuzzy 'yes'
+```
+
+### Unique results
+
+To retrieve only unique results (remove duplicates) add the following line to
+`${ZDOTDIR:-$HOME}/.zpreztorc`_:
+
+```sh
+zstyle ':prezto:module:history-substring-search' ensure-unique 'yes'
+```
+
 ## Authors
 
 _The authors of this module should be contacted via the [issue tracker][5]._
diff --git a/modules/history-substring-search/init.zsh b/modules/history-substring-search/init.zsh
index 0de78918..d287ae4d 100644
--- a/modules/history-substring-search/init.zsh
+++ b/modules/history-substring-search/init.zsh
@@ -38,6 +38,14 @@ if ! zstyle -t ':prezto:module:history-substring-search' color; then
   unset HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_{FOUND,NOT_FOUND}
 fi
 
+if zstyle -t ':prezto:module:history-substring-search' fuzzy; then
+  HISTORY_SUBSTRING_SEARCH_FUZZY=1
+fi
+
+if zstyle -t ':prezto:module:history-substring-search' ensure-unique; then
+  HISTORY_SUBSTRING_SEARCH_ENSURE_UNIQUE=1
+fi
+
 #
 # Key Bindings
 #
diff --git a/runcoms/zpreztorc b/runcoms/zpreztorc
index ae68a893..2d863c98 100644
--- a/runcoms/zpreztorc
+++ b/runcoms/zpreztorc
@@ -109,6 +109,12 @@ zstyle ':prezto:module:editor' key-bindings 'emacs'
 # Set the search globbing flags.
 # zstyle ':prezto:module:history-substring-search' globbing-flags ''
 
+# Enable fuzzy search
+# zstyle ':prezto:module:history-substring-search' fuzzy 'yes'
+
+# Retrieve only unique results (removes duplicates)
+# zstyle ':prezto:module:history-substring-search' ensure-unique 'yes'
+
 #
 # macOS
 #