Repository: mitmproxy/mitmproxy

Issue:
Flow filters don't persist between invocations of `f`
##### Steps to reproduce the problem:
1 - Hit `f` type in filter, make a typo
2 - Hit 'f' again to fix the typo

##### Expected behaviour
On second hit of f, when filter in use already the command line shows the current filter.

##### Current behaviour
On second hit of f, whn filter in use already, the filter is cleared.


##### System information
Mitmproxy 3 RC2
Flow filters don't persist between invocations of `f`
##### Steps to reproduce the problem:
1 - Hit `f` type in filter, make a typo
2 - Hit 'f' again to fix the typo

##### Expected behaviour
On second hit of f, when filter in use already the command line shows the current filter.

##### Current behaviour
On second hit of f, whn filter in use already, the filter is cleared.


##### System information
Mitmproxy 3 RC2


Discussion:
Thanks again - this is very useful UX feedback!
Also haven't found a way to copy response body to clipboard. Well no easy
way, with a single key, I think it's doable with the new command interface.
I'll make a new report if I remember.


On Tue, Jan 9, 2018 at 5:41 PM Maximilian Hils <notifications@github.com>
wrote:

> Thanks again - this is very useful UX feedback!
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <https://github.com/mitmproxy/mitmproxy/issues/2777#issuecomment-356438280>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AAg7PBeFkdn9xlcu1QFZ4427bgntlo3Jks5tI-srgaJpZM4RYgDK>
> .
>

Thanks again - this is very useful UX feedback!
Also haven't found a way to copy response body to clipboard. Well no easy
way, with a single key, I think it's doable with the new command interface.
I'll make a new report if I remember.


On Tue, Jan 9, 2018 at 5:41 PM Maximilian Hils <notifications@github.com>
wrote:

> Thanks again - this is very useful UX feedback!
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <https://github.com/mitmproxy/mitmproxy/issues/2777#issuecomment-356438280>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AAg7PBeFkdn9xlcu1QFZ4427bgntlo3Jks5tI-srgaJpZM4RYgDK>
> .
>


Resolving patch:
diff --git a/mitmproxy/tools/console/commander/commander.py b/mitmproxy/tools/console/commander/commander.py
--- a/mitmproxy/tools/console/commander/commander.py
+++ b/mitmproxy/tools/console/commander/commander.py
@@ -47,7 +47,7 @@ def cycle(self) -> str:
 )
 
 
-class CommandBuffer():
+class CommandBuffer:
     def __init__(self, master: mitmproxy.master.Master, start: str = "") -> None:
         self.master = master
         self.text = self.flatten(start)
diff --git a/mitmproxy/tools/console/consoleaddons.py b/mitmproxy/tools/console/consoleaddons.py
--- a/mitmproxy/tools/console/consoleaddons.py
+++ b/mitmproxy/tools/console/consoleaddons.py
@@ -277,6 +277,17 @@ def console_command(self, *partial: str) -> None:
         """
         signals.status_prompt_command.send(partial=" ".join(partial))  # type: ignore
 
+    @command.command("console.command.set")
+    def console_command_set(self, option: str) -> None:
+        """
+        Prompt the user to set an option of the form "key[=value]".
+        """
+        option_value = getattr(self.master.options, option, None)
+        current_value = option_value if option_value else ""
+        self.master.commands.call(
+            "console.command set %s=%s" % (option, current_value)
+        )
+
     @command.command("console.view.keybindings")
     def view_keybindings(self) -> None:
         """View the commands list."""
diff --git a/mitmproxy/tools/console/defaultkeys.py b/mitmproxy/tools/console/defaultkeys.py
--- a/mitmproxy/tools/console/defaultkeys.py
+++ b/mitmproxy/tools/console/defaultkeys.py
@@ -26,8 +26,8 @@ def map(km):
     km.add("ctrl b", "console.nav.pageup", ["global"], "Page up")
 
     km.add("I", "console.intercept.toggle", ["global"], "Toggle intercept")
-    km.add("i", "console.command set intercept=", ["global"], "Set intercept")
-    km.add("W", "console.command set save_stream_file=", ["global"], "Stream to file")
+    km.add("i", "console.command.set intercept", ["global"], "Set intercept")
+    km.add("W", "console.command.set save_stream_file", ["global"], "Stream to file")
     km.add("A", "flow.resume @all", ["flowlist", "flowview"], "Resume all intercepted flows")
     km.add("a", "flow.resume @focus", ["flowlist", "flowview"], "Resume this intercepted flow")
     km.add(
@@ -46,7 +46,7 @@ def map(km):
         ["flowlist", "flowview"],
         "Export this flow to file"
     )
-    km.add("f", "console.command set view_filter=", ["flowlist"], "Set view filter")
+    km.add("f", "console.command.set view_filter", ["flowlist"], "Set view filter")
     km.add("F", "set console_focus_follow=toggle", ["flowlist"], "Set focus follow")
     km.add(
         "ctrl l",


Test patch: