Repository: qutebrowser/qutebrowser

Issue:
Add {count} replacement / rethink how counts are handled
It would be nice to enable configuration such as
```python
config.bind('x', 'command $count')
```

So that when doing `5x`, the command `command` would be passed the argument `$count` instead of repeating itself 5 times. This is relevant in the case of a command which takes a number as argument. For instance: `tab-give`. One could then map `tg` to `tab-give $count`, then do `5tg` to move the current tab to the 5th window, i.e. the window with id `5`.




Discussion:
This simple patch would do what you want, except that window ids are mapped starting from zero, and [count] does not accept zero (i.e. you cannot do [count]tg where count=0):

```
diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py
index 3619affc5..62c6e093e 100644
--- a/qutebrowser/browser/commands.py
+++ b/qutebrowser/browser/commands.py
@@ -533,7 +533,8 @@ class CommandDispatcher:
 
     @cmdutils.register(instance='command-dispatcher', scope='window')
     @cmdutils.argument('win_id', completion=miscmodels.window)
-    def tab_give(self, win_id: int = None):
+    @cmdutils.argument('count', count=True)
+    def tab_give(self, win_id: int = None, count=None):
         """Give the current tab to a new or existing window if win_id given.
 
         If no win_id is given, the tab will get detached into a new window.
@@ -544,6 +545,8 @@ class CommandDispatcher:
         if win_id == self._win_id:
             raise cmdexc.CommandError("Can't give a tab to the same window")
 
+        if count:
+            win_id = count
         if win_id is None:
             if self._count() < 2:
                 raise cmdexc.CommandError("Cannot detach from a window with "
```
@mjauvin: will you make a PR for this? :smile: 
I also want to point out you might find binding something to `set-cmd-text` with tab-give a little more helpful, since you would get a completion list of available windows to give/take from, as opposed to giving somewhat 'blind' with the count.
@jgkamat The original feature request is fine if you have the window id in the window title. Also, when you're in a same session for a while, you can easily learn the window id of each of them. Finally, I would love even more if the idea in #3154 would be implemented so that you wouldn't have that problem as numbers (or ephemeral ids) would appear on each window beforehand.
> @jgkamat I agree, the set-cmd-text approach makes more sense to me, but not for everyone it would seem :)

That's what I use at the moment. However, it has the downside that you have to press the Enter key afterwards :smile:. But seriously, the ideal would be to have #3154 idea of hints on windows so that you don't lose time being confused about what the window ID is when looking through the completion list. The idea would be the same as using `f` key when hinting links, but for windows.
I mainly asked @sim590 to open this because it might be a good idea to rethink how to handle the count in general. We can already use an argument as count (via `:run-with-count`), but currently there's no way to do custom binds with a count involved. It'd be nice if that was possible. Maybe that could even replace the current handling of a count being a special "invisible" argument to commands.

Resolving patch:
diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py
--- a/qutebrowser/browser/commands.py
+++ b/qutebrowser/browser/commands.py
@@ -533,14 +533,19 @@ def tab_take(self, index):
 
     @cmdutils.register(instance='command-dispatcher', scope='window')
     @cmdutils.argument('win_id', completion=miscmodels.window)
-    def tab_give(self, win_id: int = None):
+    @cmdutils.argument('count', count=True)
+    def tab_give(self, win_id: int = None, count=None):
         """Give the current tab to a new or existing window if win_id given.
 
         If no win_id is given, the tab will get detached into a new window.
 
         Args:
             win_id: The window ID of the window to give the current tab to.
+            count: [count] overrides win_id (index starts at 1 for win_id=0)
         """
+        if count is not None:
+            win_id = count - 1
+
         if win_id == self._win_id:
             raise cmdexc.CommandError("Can't give a tab to the same window")
 


Test patch: