- config.py: warn and fall back to defaults on invalid keybinding fields instead of raising an unhandled ValueError - clipboard.py: replace check=True with manual returncode check for a friendly error message instead of a raw traceback - __main__.py: rename __handle_* to _handle_* (double-underscore name mangling is meaningless at module level) - rofi.py: check that rofi is installed before launching - history.py: warn on corrupted history file instead of silently returning empty - README: fix install path (cd bw-menu/python), add name to available keybinding fields
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)
|
|
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()
|