diff --git a/mitmproxy/tools/console/consoleaddons.py b/mitmproxy/tools/console/consoleaddons.py index 2a18fbb32..a65f0afe0 100644 --- a/mitmproxy/tools/console/consoleaddons.py +++ b/mitmproxy/tools/console/consoleaddons.py @@ -425,16 +425,16 @@ class ConsoleAddon: return list(sorted(keymap.Contexts)) @command.command("console.key.bind") - def key_bind(self, context: str, key: str, command: str) -> None: + def key_bind(self, contexts: typing.Sequence[str], key: str, *command: str) -> None: """ Bind a shortcut key. """ try: self.master.keymap.add( key, - command, - [context], - command + " ".join(command), + contexts, + "" ) except ValueError as v: raise exceptions.CommandError(v) @@ -477,6 +477,19 @@ class ConsoleAddon: b = self._keyfocus() self.console_command(b.command) + @command.command("console.key.edit.focus") + def key_edit_focus(self) -> None: + """ + Execute the currently focused key binding. + """ + b = self._keyfocus() + self.console_command( + "console.key.bind", + ",".join(b.contexts), + b.key, + b.command, + ) + def running(self): self.started = True diff --git a/mitmproxy/tools/console/defaultkeys.py b/mitmproxy/tools/console/defaultkeys.py index 426dd10a6..105be2be2 100644 --- a/mitmproxy/tools/console/defaultkeys.py +++ b/mitmproxy/tools/console/defaultkeys.py @@ -170,3 +170,9 @@ def map(km): ["keybindings"], "Execute the currently focused key binding" ) + km.add( + "enter", + "console.key.edit.focus", + ["keybindings"], + "Edit the currently focused key binding" + )