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) selection = selector.run(args) if selection is None: return value = rbw.get_field(selection.entry, selection.field) history.add(selection.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()