From 38edb1b16d25eaccd19aac12913f8a0b7d835b9b Mon Sep 17 00:00:00 2001 From: Panagiotis Ktistakis Date: Thu, 12 May 2016 18:46:46 +0300 Subject: [PATCH 1/5] Properly replace variables in set-cmd-text command This fixes #123 and allows variables like {url:pretty} to be used with set-cmd-text --- qutebrowser/mainwindow/statusbar/command.py | 23 ++++----------------- tests/integration/features/misc.feature | 6 +++--- 2 files changed, 7 insertions(+), 22 deletions(-) diff --git a/qutebrowser/mainwindow/statusbar/command.py b/qutebrowser/mainwindow/statusbar/command.py index f44f35126..60287374a 100644 --- a/qutebrowser/mainwindow/statusbar/command.py +++ b/qutebrowser/mainwindow/statusbar/command.py @@ -23,7 +23,7 @@ from PyQt5.QtCore import pyqtSignal, pyqtSlot, Qt, QUrl, QSize from PyQt5.QtWidgets import QSizePolicy from qutebrowser.keyinput import modeman, modeparsers -from qutebrowser.commands import cmdexc, cmdutils +from qutebrowser.commands import cmdexc, cmdutils, runners from qutebrowser.misc import cmdhistory from qutebrowser.misc import miscwidgets as misc from qutebrowser.utils import usertypes, log, objreg, qtutils @@ -105,24 +105,9 @@ class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit): space: If given, a space is added to the end. append: If given, the text is appended to the current text. """ - tabbed_browser = objreg.get('tabbed-browser', scope='window', - window=self._win_id) - if '{url}' in text: - try: - url = tabbed_browser.current_url().toString( - QUrl.FullyEncoded | QUrl.RemovePassword) - except qtutils.QtValueError as e: - msg = "Current URL is invalid" - if e.reason: - msg += " ({})".format(e.reason) - msg += "!" - raise cmdexc.CommandError(msg) - # FIXME we currently replace the URL in any place in the arguments, - # rather than just replacing it if it is a dedicated argument. We - # could split the args, but then trailing spaces would be lost, so - # I'm not sure what's the best thing to do here - # https://github.com/The-Compiler/qutebrowser/issues/123 - text = text.replace('{url}', url) + args = text.split() + args = runners.replace_variables(self._win_id, args) + text = ' '.join(args) if space: text += ' ' diff --git a/tests/integration/features/misc.feature b/tests/integration/features/misc.feature index 13a3c33c6..d2edfa4b3 100644 --- a/tests/integration/features/misc.feature +++ b/tests/integration/features/misc.feature @@ -15,9 +15,9 @@ Feature: Various utility commands. Scenario: :set-cmd-text with URL replacement When I open data/hello.txt - When I run :set-cmd-text :message-info >{url}< + When I run :set-cmd-text :message-info {url} And I run :command-accept - Then the message ">http://localhost:*/hello.txt<" should be shown + Then the message "http://localhost:*/hello.txt" should be shown Scenario: :set-cmd-text with -s and -a When I run :set-cmd-text -s :message-info "foo @@ -342,7 +342,7 @@ Feature: Various utility commands. Scenario: Running :pyeval with --quiet When I run :debug-pyeval --quiet 1+1 Then "pyeval output: 2" should be logged - + ## https://github.com/The-Compiler/qutebrowser/issues/504 Scenario: Focusing download widget via Tab From 7488f2a5cb9ef0fb23053266465c03e49a82f833 Mon Sep 17 00:00:00 2001 From: Panagiotis Ktistakis Date: Fri, 13 May 2016 18:45:44 +0300 Subject: [PATCH 2/5] Remove unused imports --- qutebrowser/mainwindow/statusbar/command.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qutebrowser/mainwindow/statusbar/command.py b/qutebrowser/mainwindow/statusbar/command.py index 60287374a..dee11b68f 100644 --- a/qutebrowser/mainwindow/statusbar/command.py +++ b/qutebrowser/mainwindow/statusbar/command.py @@ -19,14 +19,14 @@ """The commandline in the statusbar.""" -from PyQt5.QtCore import pyqtSignal, pyqtSlot, Qt, QUrl, QSize +from PyQt5.QtCore import pyqtSignal, pyqtSlot, Qt, QSize from PyQt5.QtWidgets import QSizePolicy from qutebrowser.keyinput import modeman, modeparsers from qutebrowser.commands import cmdexc, cmdutils, runners from qutebrowser.misc import cmdhistory from qutebrowser.misc import miscwidgets as misc -from qutebrowser.utils import usertypes, log, objreg, qtutils +from qutebrowser.utils import usertypes, log, objreg class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit): From ecfa6cfc636cde4347a78e51749482f0313df668 Mon Sep 17 00:00:00 2001 From: Panagiotis Ktistakis Date: Fri, 13 May 2016 18:51:02 +0300 Subject: [PATCH 3/5] Split arguments using qutebrowser.utils.split --- qutebrowser/mainwindow/statusbar/command.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qutebrowser/mainwindow/statusbar/command.py b/qutebrowser/mainwindow/statusbar/command.py index dee11b68f..edf93a007 100644 --- a/qutebrowser/mainwindow/statusbar/command.py +++ b/qutebrowser/mainwindow/statusbar/command.py @@ -24,7 +24,7 @@ from PyQt5.QtWidgets import QSizePolicy from qutebrowser.keyinput import modeman, modeparsers from qutebrowser.commands import cmdexc, cmdutils, runners -from qutebrowser.misc import cmdhistory +from qutebrowser.misc import cmdhistory, split from qutebrowser.misc import miscwidgets as misc from qutebrowser.utils import usertypes, log, objreg @@ -105,7 +105,7 @@ class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit): space: If given, a space is added to the end. append: If given, the text is appended to the current text. """ - args = text.split() + args = split.split(text, keep=True) args = runners.replace_variables(self._win_id, args) text = ' '.join(args) From bb45392c1b87bed8b26eeaf27e04c9af96cec78e Mon Sep 17 00:00:00 2001 From: Panagiotis Ktistakis Date: Fri, 13 May 2016 19:32:35 +0300 Subject: [PATCH 4/5] Use the right split function --- qutebrowser/mainwindow/statusbar/command.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qutebrowser/mainwindow/statusbar/command.py b/qutebrowser/mainwindow/statusbar/command.py index edf93a007..a8cc0c16c 100644 --- a/qutebrowser/mainwindow/statusbar/command.py +++ b/qutebrowser/mainwindow/statusbar/command.py @@ -105,7 +105,7 @@ class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit): space: If given, a space is added to the end. append: If given, the text is appended to the current text. """ - args = split.split(text, keep=True) + args = split.simple_split(text) args = runners.replace_variables(self._win_id, args) text = ' '.join(args) From 9527712daa2bb135cc960f971abcaa9651e9d165 Mon Sep 17 00:00:00 2001 From: Panagiotis Ktistakis Date: Sat, 14 May 2016 18:44:05 +0300 Subject: [PATCH 5/5] Add tests for {url:pretty} in :set-cmd-text --- tests/integration/features/misc.feature | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/integration/features/misc.feature b/tests/integration/features/misc.feature index d2edfa4b3..1356a3cf3 100644 --- a/tests/integration/features/misc.feature +++ b/tests/integration/features/misc.feature @@ -15,10 +15,22 @@ Feature: Various utility commands. Scenario: :set-cmd-text with URL replacement When I open data/hello.txt - When I run :set-cmd-text :message-info {url} + And I run :set-cmd-text :message-info {url} And I run :command-accept Then the message "http://localhost:*/hello.txt" should be shown + Scenario: :set-cmd-text with URL replacement with encoded spaces + When I open data/title with spaces.html + And I run :set-cmd-text :message-info {url} + And I run :command-accept + Then the message "http://localhost:*/title%20with%20spaces.html" should be shown + + Scenario: :set-cmd-text with URL replacement with decoded spaces + When I open data/title with spaces.html + And I run :set-cmd-text :message-info "> {url:pretty} <" + And I run :command-accept + Then the message "> http://localhost:*/title with spaces.html <" should be shown + Scenario: :set-cmd-text with -s and -a When I run :set-cmd-text -s :message-info "foo And I run :set-cmd-text -a bar"