Replace --custom-field, --kb-accept, and --kb-custom CLI flags with a YAML config file at $XDG_CONFIG_HOME/bw-menu/config.yaml. The config maps rofi key names to vault fields (e.g. Return: password), making keybinding configuration simpler and more intuitive.
44 lines
1.3 KiB
Python
44 lines
1.3 KiB
Python
import subprocess
|
|
|
|
from bw_menu import rbw, history
|
|
from bw_menu.selector import Selection, format_entry, encode_info, decode_info
|
|
|
|
|
|
class FzfSelector:
|
|
def run(self, args) -> Selection | None:
|
|
all_entries = rbw.list_entries()
|
|
history_entries = history.load()
|
|
|
|
all_set = set(all_entries)
|
|
history_in_list = [e for e in history_entries if e in all_set]
|
|
history_set = set(history_in_list)
|
|
remaining = [e for e in all_entries if e not in history_set]
|
|
remaining.sort(key=lambda e: (e.folder.lower(), e.name.lower()))
|
|
|
|
lines = []
|
|
for entry in history_in_list:
|
|
display = f"* {format_entry(entry)}"
|
|
lines.append(f"{display}\t{encode_info(entry)}")
|
|
for entry in remaining:
|
|
display = f" {format_entry(entry)}"
|
|
lines.append(f"{display}\t{encode_info(entry)}")
|
|
|
|
input_text = "\n".join(lines)
|
|
|
|
result = subprocess.run(
|
|
["fzf", "--no-sort", "-d", "\t", "--with-nth=1"],
|
|
input=input_text,
|
|
stdout=subprocess.PIPE,
|
|
encoding="utf-8",
|
|
)
|
|
|
|
if result.returncode != 0:
|
|
return None
|
|
|
|
selected = result.stdout.strip()
|
|
parts = selected.split("\t", 1)
|
|
if len(parts) < 2:
|
|
return None
|
|
|
|
return Selection(decode_info(parts[1]), args.field)
|