diff --git a/doc/help/commands.asciidoc b/doc/help/commands.asciidoc index be017a2c3..bc4b435f9 100644 --- a/doc/help/commands.asciidoc +++ b/doc/help/commands.asciidoc @@ -1519,7 +1519,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. @@ -1528,6 +1528,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 ebce4b37a..9fa6dba86 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -945,7 +945,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, 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,6 +957,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) @@ -965,7 +966,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 new: + self.openurl(index, tab=True) + return + raise window = tabbed_browser.widget.window() mainwindow.raise_window(window)