diff --git a/doc/help/commands.asciidoc b/doc/help/commands.asciidoc index 3d60cce64..6daff3bcc 100644 --- a/doc/help/commands.asciidoc +++ b/doc/help/commands.asciidoc @@ -918,6 +918,9 @@ Repeat a given command. * +'times'+: How many times to repeat. * +'command'+: The command to run, with optional args. +==== count +Multiplies with 'times' when given. + ==== note * This command does not split arguments after the last argument and handles quotes literally. * With this command, +;;+ is interpreted literally instead of splitting off a second command. diff --git a/qutebrowser/misc/utilcmds.py b/qutebrowser/misc/utilcmds.py index 702c62cac..d108a56ac 100644 --- a/qutebrowser/misc/utilcmds.py +++ b/qutebrowser/misc/utilcmds.py @@ -74,13 +74,18 @@ def later(ms: int, command, win_id): @cmdutils.register(maxsplit=1, no_cmd_split=True, no_replace_variables=True) @cmdutils.argument('win_id', win_id=True) -def repeat(times: int, command, win_id): +@cmdutils.argument('count', count=True) +def repeat(times: int, command, win_id, count=None): """Repeat a given command. Args: times: How many times to repeat. command: The command to run, with optional args. + count: Multiplies with 'times' when given. """ + if count is not None: + times *= count + if times < 0: raise cmdexc.CommandError("A negative count doesn't make sense.") commandrunner = runners.CommandRunner(win_id) diff --git a/tests/end2end/features/utilcmds.feature b/tests/end2end/features/utilcmds.feature index 5ccbac9b3..fac335813 100644 --- a/tests/end2end/features/utilcmds.feature +++ b/tests/end2end/features/utilcmds.feature @@ -41,6 +41,15 @@ Feature: Miscellaneous utility commands exposed to the user. # If we have an error, the test will fail Then no crash should happen + Scenario: :repeat with count + When I run :repeat 3 message-info "repeat-test 3" with count 2 + Then the message "repeat-test 3" should be shown + And the message "repeat-test 3" should be shown + And the message "repeat-test 3" should be shown + And the message "repeat-test 3" should be shown + And the message "repeat-test 3" should be shown + And the message "repeat-test 3" should be shown + ## :run-with-count Scenario: :run-with-count