From fab921066aea41667a04c0308af753754c1e735c Mon Sep 17 00:00:00 2001 From: Navid Sassan Date: Tue, 17 Feb 2026 22:08:00 +0100 Subject: [PATCH] =?UTF-8?q?Flip=20config=20keybinding=20format=20to=20fiel?= =?UTF-8?q?d=20=E2=86=92=20key=20and=20clear=20conflicting=20rofi=20defaul?= =?UTF-8?q?ts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 26 +++++++++++++++++--------- src/bw_menu/config.py | 4 ++-- src/bw_menu/selector/rofi.py | 17 +++++++++++++---- 3 files changed, 32 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 661fee6..229224b 100644 --- a/README.md +++ b/README.md @@ -54,15 +54,7 @@ Default keybindings: | Ctrl+Enter | Copy **username** | | Escape | Cancel | -Keybindings are configurable via `$XDG_CONFIG_HOME/bw-menu/config.yaml` (defaults to `~/.config/bw-menu/config.yaml`): - -```yaml -keybindings: - Return: password - Control+Return: username -``` - -Each entry maps a rofi key name to the vault field it copies. The first entry is bound to rofi's accept key, additional entries become custom keybindings. +Keybindings are configurable — see [Configuration](#configuration) for details. ### fzf @@ -90,6 +82,22 @@ The selected field is copied to the clipboard using `wl-copy` (Wayland) or `xcli Selections are saved to `$XDG_CACHE_HOME/bw-menu/history.json` (defaults to `~/.cache/bw-menu/history.json`), up to 10 entries. The most recent selection is at index 0. +## Configuration + +Config file location: `$XDG_CONFIG_HOME/bw-menu/config.yaml` (defaults to `~/.config/bw-menu/config.yaml`). + +```yaml +keybindings: + password: Return + username: Control+Return + totp: Control+Shift+Return +``` + +Each entry maps a vault field to a [rofi key name](https://davatorium.github.io/rofi/current/rofi-keys.5/). Available fields: `password`, `username`, `totp`. + +The **first** entry is bound to rofi's accept key (`kb-accept-entry`). Additional entries become custom keybindings (`kb-custom-1`, `kb-custom-2`, …). + + ## Sway keybindings Example keybindings for `~/.config/sway/config`: diff --git a/src/bw_menu/config.py b/src/bw_menu/config.py index 4224e9f..f4b98ff 100644 --- a/src/bw_menu/config.py +++ b/src/bw_menu/config.py @@ -6,7 +6,7 @@ from pathlib import Path import yaml -DEFAULT_KEYBINDINGS = {"Return": "password", "Control+Return": "username"} +DEFAULT_KEYBINDINGS = {"password": "Return", "username": "Control+Return"} VALID_FIELDS = {"password", "username", "totp"} @@ -43,7 +43,7 @@ def load() -> Config: ) return Config() keybindings = {str(k): str(v) for k, v in kb.items()} - invalid = {v for v in keybindings.values() if v not in VALID_FIELDS} + invalid = {k for k in keybindings if k not in VALID_FIELDS} if invalid: raise ValueError( f"Invalid keybinding field(s): {', '.join(sorted(invalid))}. Valid fields: {', '.join(sorted(VALID_FIELDS))}" diff --git a/src/bw_menu/selector/rofi.py b/src/bw_menu/selector/rofi.py index b69e99f..bb773c9 100644 --- a/src/bw_menu/selector/rofi.py +++ b/src/bw_menu/selector/rofi.py @@ -34,7 +34,7 @@ class RofiSelector: self.__print_entries(keybindings) return None - fields = list(keybindings.values()) + fields = list(keybindings.keys()) # kb-accept-entry → first field if rofi_retv == 1: @@ -77,7 +77,7 @@ class RofiSelector: def __launch(self, keybindings: dict[str, str]): script = str(Path(sys.argv[0]).resolve()) - keys = list(keybindings.keys()) + keys = list(keybindings.values()) # Clean up any stale result from a previous run _result_path().unlink(missing_ok=True) @@ -91,7 +91,16 @@ class RofiSelector: "-kb-accept-entry", keys[0], ] - cmd.extend(["-kb-accept-custom", ""]) + cmd.extend( + [ + "-kb-accept-custom", + "", + "-kb-accept-alt", + "", + "-kb-accept-custom-alt", + "", + ] + ) for i, key in enumerate(keys[1:], start=1): cmd.extend([f"-kb-custom-{i}", key]) @@ -105,7 +114,7 @@ class RofiSelector: print("\0use-hot-keys\x1ftrue") hints = [] - for key, field in keybindings.items(): + for field, key in keybindings.items(): label = key.replace("+", " + ") hints.append(f"{label}: {field}") print(f"\0message\x1f{' | '.join(hints)}")