summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2021-04-04 13:15:56 +0200
committerFlorian Bruhin <me@the-compiler.org>2021-04-04 13:15:56 +0200
commita8d5ce13e8dd3e996d839d3bb80d2f391ff37100 (patch)
treefe3dbe3c2f06e7456d22d883cf41ad278b8b0d74
parented45c7fdc59ac376dc4b9a51811760aaabbd8ad8 (diff)
downloadqutebrowser-a8d5ce13e8dd3e996d839d3bb80d2f391ff37100.tar.gz
qutebrowser-a8d5ce13e8dd3e996d839d3bb80d2f391ff37100.zip
Add URL pattern support for :config-unset
See #5856
-rw-r--r--doc/changelog.asciidoc3
-rw-r--r--doc/help/commands.asciidoc3
-rw-r--r--qutebrowser/config/configcommands.py13
-rw-r--r--tests/unit/config/test_configcommands.py19
4 files changed, 35 insertions, 3 deletions
diff --git a/doc/changelog.asciidoc b/doc/changelog.asciidoc
index 6e03aa68b..d1708fd90 100644
--- a/doc/changelog.asciidoc
+++ b/doc/changelog.asciidoc
@@ -105,6 +105,9 @@ Changed
- The default binding for `T` (`:tab-focus`) got changed so that it fills the
command line with `:tab-focus` if used without a count (instead of being
equivalent to `:tab-next` in that case).
+- The `:config-unset` command now understands the `--pattern` (`-u`) flag to
+ unset options customized for a given URL pattern (such as after answering a
+ prompt with "always"/"never").
Fixed
~~~~~
diff --git a/doc/help/commands.asciidoc b/doc/help/commands.asciidoc
index 8eca20caf..d8a6e761c 100644
--- a/doc/help/commands.asciidoc
+++ b/doc/help/commands.asciidoc
@@ -381,7 +381,7 @@ Read a config.py file.
[[config-unset]]
=== config-unset
-Syntax: +:config-unset [*--temp*] 'option'+
+Syntax: +:config-unset [*--pattern* 'pattern'] [*--temp*] 'option'+
Unset an option.
@@ -391,6 +391,7 @@ This sets an option back to its default and removes it from autoconfig.yml.
* +'option'+: The name of the option.
==== optional arguments
+* +*-u*+, +*--pattern*+: The URL pattern to use.
* +*-t*+, +*--temp*+: Set value temporarily until qutebrowser is closed.
[[config-write-py]]
diff --git a/qutebrowser/config/configcommands.py b/qutebrowser/config/configcommands.py
index afec3d5aa..f76ece066 100644
--- a/qutebrowser/config/configcommands.py
+++ b/qutebrowser/config/configcommands.py
@@ -244,7 +244,14 @@ class ConfigCommands:
@cmdutils.register(instance='config-commands')
@cmdutils.argument('option', completion=configmodel.customized_option)
- def config_unset(self, option: str, temp: bool = False) -> None:
+ @cmdutils.argument('pattern', flag='u')
+ def config_unset(
+ self,
+ option: str,
+ *,
+ pattern: str = None,
+ temp: bool = False,
+ ) -> None:
"""Unset an option.
This sets an option back to its default and removes it from
@@ -252,10 +259,12 @@ class ConfigCommands:
Args:
option: The name of the option.
+ pattern: The URL pattern to use.
temp: Set value temporarily until qutebrowser is closed.
"""
+ parsed_pattern = self._parse_pattern(pattern)
with self._handle_config_error():
- self._config.unset(option, save_yaml=not temp)
+ self._config.unset(option, save_yaml=not temp, pattern=parsed_pattern)
@cmdutils.register(instance='config-commands')
@cmdutils.argument('win_id', value=cmdutils.Value.win_id)
diff --git a/tests/unit/config/test_configcommands.py b/tests/unit/config/test_configcommands.py
index 72af2ad3e..6aa5d3c11 100644
--- a/tests/unit/config/test_configcommands.py
+++ b/tests/unit/config/test_configcommands.py
@@ -460,6 +460,25 @@ class TestUnsetAndClear:
with pytest.raises(cmdutils.CommandError, match="No option 'tabs'"):
commands.config_unset('tabs')
+ @pytest.mark.parametrize('set_global', [True, False])
+ def test_unset_pattern(self, commands, config_stub, set_global):
+ name = 'content.javascript.enabled'
+ pattern = urlmatch.UrlPattern('*://example.com')
+ url = QUrl('https://example.com')
+
+ if set_global:
+ config_stub.set_obj(name, False)
+ global_value = False
+ local_value = True
+ else:
+ global_value = True
+ local_value = False
+
+ config_stub.set_obj(name, local_value, pattern=pattern)
+ commands.config_unset(name, pattern=str(pattern))
+ assert config_stub.get_obj(name, url=url) == global_value
+ assert config_stub.get_obj(name, url=url, fallback=False) == usertypes.UNSET
+
@pytest.mark.parametrize('save', [True, False])
def test_clear(self, commands, config_stub, yaml_value, save):
name = 'tabs.show'