Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Features
* Added explicit error handle to get_password_from_file with EAFP.
* Use the "history" scheme for fzf searches.
* Deduplicate history in fzf searches.
* Add a preview window to fzf history searches.

Internal
--------
Expand Down
8 changes: 6 additions & 2 deletions mycli/packages/toolkit/fzf.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
from shutil import which

from pyfzf import FzfPrompt
Expand Down Expand Up @@ -30,15 +31,18 @@ def search_history(event: KeyPressEvent):
original_history_items = []
seen = {}
for item, timestamp in history_items_with_timestamp:
formatted_item = item.replace("\n", " ")
formatted_item = re.sub(r'\s+', ' ', item)
timestamp = timestamp.split(".")[0] if "." in timestamp else timestamp
if formatted_item in seen:
continue
seen[formatted_item] = True
formatted_history_items.append(f"{timestamp} {formatted_item}")
original_history_items.append(item)

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

if result:
selected_index = formatted_history_items.index(result[0])
Expand Down