Replace bw-serve/Ansible-based implementation with a clean rewrite: - rbw CLI wrapper for listing entries and fetching credentials - Rofi script-mode and fzf selectors with history-first sorting - JSON-backed frecency history at ~/.cache/bw-menu/ - Clipboard support via wl-copy/xclip auto-detection - uv + hatchling packaging with bw-menu entry point
52 lines
1.2 KiB
Python
52 lines
1.2 KiB
Python
import sys
|
|
|
|
from bw_menu import rbw, history, clipboard
|
|
from bw_menu.cli import parse_args
|
|
from bw_menu.selector import format_entry, create_selector
|
|
|
|
|
|
def main():
|
|
args = parse_args()
|
|
|
|
if args.command == "select":
|
|
__handle_select(args)
|
|
elif args.command == "history":
|
|
__handle_history(args)
|
|
|
|
|
|
def __handle_select(args):
|
|
selector = create_selector(args.selector)
|
|
entry = selector.run(args)
|
|
if entry is None:
|
|
return
|
|
|
|
value = rbw.get_field(entry, args.field)
|
|
history.add(entry)
|
|
|
|
if args.print_result:
|
|
print(value)
|
|
else:
|
|
clipboard.copy(value)
|
|
|
|
|
|
def __handle_history(args):
|
|
if args.history_command == "list":
|
|
for i, entry in enumerate(history.load()):
|
|
print(f"{i}: {format_entry(entry)}")
|
|
|
|
elif args.history_command == "get":
|
|
entry = history.get(args.index)
|
|
if entry is None:
|
|
print(f"No history entry at index {args.index}", file=sys.stderr)
|
|
sys.exit(1)
|
|
|
|
value = rbw.get_field(entry, args.field)
|
|
if args.print_result:
|
|
print(value)
|
|
else:
|
|
clipboard.copy(value)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|