diff --git a/doc/changelog.asciidoc b/doc/changelog.asciidoc index 41515d287..a4f5e50a5 100644 --- a/doc/changelog.asciidoc +++ b/doc/changelog.asciidoc @@ -34,6 +34,8 @@ Added are used for hints, and also allows adding custom hint groups. - New `:yank markdown` feature which yanks the current URL and title in markdown format. +- New command `:navigate strip` which removes queries and parameters from the + current URL (bound to `gs`/`gS` by default). Changed ~~~~~~~ diff --git a/doc/help/commands.asciidoc b/doc/help/commands.asciidoc index 13cf0a790..6149d5247 100644 --- a/doc/help/commands.asciidoc +++ b/doc/help/commands.asciidoc @@ -827,6 +827,7 @@ This tries to automatically click on typical _Previous Page_ or _Next Page_ link Uses the link:settings{outsuffix}#url.incdec_segments[url.incdec_segments] config option. + - `strip`: Strip parameters from the current URL. diff --git a/doc/help/settings.asciidoc b/doc/help/settings.asciidoc index b7cb0349b..91125c2eb 100644 --- a/doc/help/settings.asciidoc +++ b/doc/help/settings.asciidoc @@ -575,6 +575,7 @@ Default: * +pass:[gC]+: +pass:[tab-clone]+ * +pass:[gD]+: +pass:[tab-give]+ * +pass:[gO]+: +pass:[set-cmd-text :open -t -r {url:pretty}]+ +* +pass:[gS]+: +pass:[navigate strip -t]+ * +pass:[gU]+: +pass:[navigate up -t]+ * +pass:[g^]+: +pass:[tab-focus 1]+ * +pass:[ga]+: +pass:[open -t]+ @@ -587,6 +588,7 @@ Default: * +pass:[gm]+: +pass:[tab-move]+ * +pass:[go]+: +pass:[set-cmd-text :open {url:pretty}]+ * +pass:[gr]+: +pass:[tab-move +]+ +* +pass:[gs]+: +pass:[navigate strip]+ * +pass:[gt]+: +pass:[set-cmd-text -s :buffer]+ * +pass:[gu]+: +pass:[navigate up]+ * +pass:[h]+: +pass:[scroll left]+ diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index ceafbc011..7beb53c89 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -599,7 +599,7 @@ class CommandDispatcher: @cmdutils.register(instance='command-dispatcher', scope='window') @cmdutils.argument('where', choices=['prev', 'next', 'up', 'increment', - 'decrement']) + 'decrement', 'strip']) @cmdutils.argument('count', count=True) def navigate(self, where: str, tab=False, bg=False, window=False, count=1): """Open typical prev/next links or navigate using the URL path. @@ -623,6 +623,7 @@ class CommandDispatcher: Uses the link:settings{outsuffix}#url.incdec_segments[url.incdec_segments] config option. + - `strip`: Strip parameters from the current URL. tab: Open in a new tab. bg: Open in a background tab. @@ -657,6 +658,9 @@ class CommandDispatcher: url = url.adjusted(QUrl.RemoveFragment | QUrl.RemoveQuery) new_url = handlers[where](url, count) self._open(new_url, tab, bg, window, related=True) + elif where == 'strip': + url = url.adjusted(QUrl.RemoveFragment | QUrl.RemoveQuery) + self._open(url, tab, bg, window, related=True) else: # pragma: no cover raise ValueError("Got called with invalid value {} for " "`where'.".format(where)) diff --git a/qutebrowser/config/configdata.yml b/qutebrowser/config/configdata.yml index ff43cc156..b6c58f4aa 100644 --- a/qutebrowser/config/configdata.yml +++ b/qutebrowser/config/configdata.yml @@ -2646,6 +2646,8 @@ bindings.default: "}}": navigate next -t gu: navigate up gU: navigate up -t + gs: navigate strip + gS: navigate strip -t : navigate increment : navigate decrement wi: inspector diff --git a/tests/end2end/features/navigate.feature b/tests/end2end/features/navigate.feature index 07bd56c69..b555cdfda 100644 --- a/tests/end2end/features/navigate.feature +++ b/tests/end2end/features/navigate.feature @@ -4,7 +4,7 @@ Feature: Using :navigate Scenario: :navigate with invalid argument When I run :navigate foo - Then the error "where: Invalid value foo - expected one of: prev, next, up, increment, decrement" should be shown + Then the error "where: Invalid value foo - expected one of: prev, next, up, increment, decrement, strip" should be shown # up @@ -136,3 +136,20 @@ Feature: Using :navigate When I open data/navigate/multilinelinks.html And I run :navigate next Then data/numbers/5.txt should be loaded + + # strip + + Scenario: Stripping a query + When I open data/navigate?foo=bar + And I run :navigate strip + Then data/navigate should be loaded + + Scenario: Stripping a label + When I open data/navigate#label + And I run :navigate strip + Then data/navigate should be loaded + + Scenario: Stripping a query and a label + When I open data/navigate?foo=bar#label + And I run :navigate strip + Then data/navigate should be loaded