Skip to content

Commit 299e874

Browse files
authored
Merge pull request #1210 from dbcli/RW/fuzzy-search-preview-window
Add a preview window to fuzzy history search
2 parents 6457b3a + 70e137b commit 299e874

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Features
66
* Added explicit error handle to get_password_from_file with EAFP.
77
* Use the "history" scheme for fzf searches.
88
* Deduplicate history in fzf searches.
9+
* Add a preview window to fzf history searches.
910

1011
Internal
1112
--------

mycli/packages/toolkit/fzf.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import re
12
from shutil import which
23

34
from pyfzf import FzfPrompt
@@ -30,15 +31,18 @@ def search_history(event: KeyPressEvent):
3031
original_history_items = []
3132
seen = {}
3233
for item, timestamp in history_items_with_timestamp:
33-
formatted_item = item.replace("\n", " ")
34+
formatted_item = re.sub(r'\s+', ' ', item)
3435
timestamp = timestamp.split(".")[0] if "." in timestamp else timestamp
3536
if formatted_item in seen:
3637
continue
3738
seen[formatted_item] = True
3839
formatted_history_items.append(f"{timestamp} {formatted_item}")
3940
original_history_items.append(item)
4041

41-
result = fzf.prompt(formatted_history_items, fzf_options="--scheme=history --tiebreak=index")
42+
result = fzf.prompt(
43+
formatted_history_items,
44+
fzf_options="--scheme=history --tiebreak=index --preview-window=down:wrap --preview=\"printf '%s' {}\"",
45+
)
4246

4347
if result:
4448
selected_index = formatted_history_items.index(result[0])

0 commit comments

Comments
 (0)