From 81ff5abbfe20c19719e9a16606b44b6ea878751a Mon Sep 17 00:00:00 2001 From: Max Date: Mon, 22 Aug 2022 19:48:04 +0600 Subject: [PATCH 1/2] added --open arg to :tab-select --- doc/help/commands.asciidoc | 4 +++- qutebrowser/browser/commands.py | 12 ++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/doc/help/commands.asciidoc b/doc/help/commands.asciidoc index b1ba0b83c..4e1bfd1ee 100644 --- a/doc/help/commands.asciidoc +++ b/doc/help/commands.asciidoc @@ -1504,7 +1504,7 @@ How many tabs to switch back. [[tab-select]] === tab-select -Syntax: +:tab-select ['index']+ +Syntax: +:tab-select [*--open*] ['index']+ Select tab by index or url/title best match. @@ -1513,6 +1513,8 @@ Focuses window if necessary when index is given. If both index and count are giv ==== positional arguments * +'index'+: The [win_id/]index of the tab to focus. Or a substring in which case the closest match will be focused. +==== optional arguments +* +*-o*+, +*--open*+: If index is a substring and it didn't match any tab, open it in a new tab. ==== count The tab index to focus, starting with 1. diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index e6d2af822..e0078561d 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -932,7 +932,7 @@ class CommandDispatcher: maxsplit=0) @cmdutils.argument('index', completion=miscmodels.tabs) @cmdutils.argument('count', value=cmdutils.Value.count) - def tab_select(self, index=None, count=None): + def tab_select(self, index=None, open=False, count=None): """Select tab by index or url/title best match. Focuses window if necessary when index is given. If both index and @@ -944,6 +944,7 @@ class CommandDispatcher: index: The [win_id/]index of the tab to focus. Or a substring in which case the closest match will be focused. count: The tab index to focus, starting with 1. + open: If index is a substring and it didn't match any tab, open it in a new tab. """ if count is None and index is None: self.openurl('qute://tabs/', tab=True) @@ -952,7 +953,14 @@ class CommandDispatcher: if count is not None: index = str(count) - tabbed_browser, tab = self._resolve_tab_index(index) + tabbed_browser, tab = None, None + try: + tabbed_browser, tab = self._resolve_tab_index(index) + except cmdutils.CommandError: + if open: + self.openurl(index, tab=True) + return + raise window = tabbed_browser.widget.window() mainwindow.raise_window(window) From 6e6083caf2cb5b0c086f62a2cdf5fd61f03a7eff Mon Sep 17 00:00:00 2001 From: Max Date: Mon, 22 Aug 2022 20:07:45 +0600 Subject: [PATCH 2/2] --open --> --new --- qutebrowser/browser/commands.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index e0078561d..144e36268 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -932,7 +932,7 @@ class CommandDispatcher: maxsplit=0) @cmdutils.argument('index', completion=miscmodels.tabs) @cmdutils.argument('count', value=cmdutils.Value.count) - def tab_select(self, index=None, open=False, count=None): + def tab_select(self, index=None, new=False, count=None): """Select tab by index or url/title best match. Focuses window if necessary when index is given. If both index and @@ -957,7 +957,7 @@ class CommandDispatcher: try: tabbed_browser, tab = self._resolve_tab_index(index) except cmdutils.CommandError: - if open: + if new: self.openurl(index, tab=True) return raise