Add type-based icons to rofi entries
Parse the `type` field from `rbw list --raw` (Login, SecureNote, Card, Identity) and display a corresponding icon for each entry in rofi. History entries keep their `document-open-recent` icon. The type field uses `compare=False` so it doesn't affect entry identity or history matching.
This commit is contained in:
parent
9b080f6b07
commit
23c825a71c
@ -1,6 +1,6 @@
|
|||||||
import json
|
import json
|
||||||
import sys
|
import sys
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass, field
|
||||||
from subprocess import run
|
from subprocess import run
|
||||||
|
|
||||||
|
|
||||||
@ -9,6 +9,7 @@ class Entry:
|
|||||||
name: str
|
name: str
|
||||||
folder: str
|
folder: str
|
||||||
username: str
|
username: str
|
||||||
|
type: str = field(default="Login", compare=False)
|
||||||
|
|
||||||
|
|
||||||
def list_entries() -> list[Entry]:
|
def list_entries() -> list[Entry]:
|
||||||
@ -21,7 +22,13 @@ def list_entries() -> list[Entry]:
|
|||||||
|
|
||||||
data = json.loads(result.stdout.strip())
|
data = json.loads(result.stdout.strip())
|
||||||
return [
|
return [
|
||||||
Entry(item["name"], item["folder"] or "", item["user"] or "") for item in data
|
Entry(
|
||||||
|
item["name"],
|
||||||
|
item["folder"] or "",
|
||||||
|
item["user"] or "",
|
||||||
|
item.get("type", "Login"),
|
||||||
|
)
|
||||||
|
for item in data
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -36,8 +36,8 @@ def prepare_entries() -> tuple[list[Entry], list[Entry]]:
|
|||||||
all_entries = rbw.list_entries()
|
all_entries = rbw.list_entries()
|
||||||
history_entries = history.load()
|
history_entries = history.load()
|
||||||
|
|
||||||
all_set = set(all_entries)
|
all_dict = {e: e for e in all_entries}
|
||||||
history_in_list = [e for e in history_entries if e in all_set]
|
history_in_list = [all_dict[e] for e in history_entries if e in all_dict]
|
||||||
history_set = set(history_in_list)
|
history_set = set(history_in_list)
|
||||||
remaining = [e for e in all_entries if e not in history_set]
|
remaining = [e for e in all_entries if e not in history_set]
|
||||||
remaining.sort(key=lambda e: (e.folder.lower(), e.name.lower()))
|
remaining.sort(key=lambda e: (e.folder.lower(), e.name.lower()))
|
||||||
|
|||||||
@ -18,6 +18,14 @@ def _result_path() -> Path:
|
|||||||
return Path(cache_dir) / "bw-menu" / "result"
|
return Path(cache_dir) / "bw-menu" / "result"
|
||||||
|
|
||||||
|
|
||||||
|
_TYPE_ICONS: dict[str, str] = {
|
||||||
|
"Login": "dialog-password",
|
||||||
|
"SecureNote": "text-x-generic",
|
||||||
|
"Card": "credit-card",
|
||||||
|
"Identity": "contact-new",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class RofiSelector:
|
class RofiSelector:
|
||||||
def run(self, args) -> Selection | None:
|
def run(self, args) -> Selection | None:
|
||||||
cfg = config.load()
|
cfg = config.load()
|
||||||
@ -127,4 +135,5 @@ class RofiSelector:
|
|||||||
|
|
||||||
for entry in remaining:
|
for entry in remaining:
|
||||||
display = format_entry(entry)
|
display = format_entry(entry)
|
||||||
print(f"{display}\0info\x1f{encode_info(entry)}")
|
icon = _TYPE_ICONS.get(entry.type, "dialog-password")
|
||||||
|
print(f"{display}\0info\x1f{encode_info(entry)}\x1ficon\x1f{icon}")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user