Properly replace variables in set-cmd-text command

This fixes #123 and allows variables like {url:pretty} to be used with
set-cmd-text
This commit is contained in:
Panagiotis Ktistakis 2016-05-12 18:46:46 +03:00
parent a9a853baf0
commit 38edb1b16d
2 changed files with 7 additions and 22 deletions

View File

@ -23,7 +23,7 @@ from PyQt5.QtCore import pyqtSignal, pyqtSlot, Qt, QUrl, QSize
from PyQt5.QtWidgets import QSizePolicy from PyQt5.QtWidgets import QSizePolicy
from qutebrowser.keyinput import modeman, modeparsers 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 cmdhistory
from qutebrowser.misc import miscwidgets as misc from qutebrowser.misc import miscwidgets as misc
from qutebrowser.utils import usertypes, log, objreg, qtutils 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. space: If given, a space is added to the end.
append: If given, the text is appended to the current text. append: If given, the text is appended to the current text.
""" """
tabbed_browser = objreg.get('tabbed-browser', scope='window', args = text.split()
window=self._win_id) args = runners.replace_variables(self._win_id, args)
if '{url}' in text: text = ' '.join(args)
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)
if space: if space:
text += ' ' text += ' '

View File

@ -15,9 +15,9 @@ Feature: Various utility commands.
Scenario: :set-cmd-text with URL replacement Scenario: :set-cmd-text with URL replacement
When I open data/hello.txt 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 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 Scenario: :set-cmd-text with -s and -a
When I run :set-cmd-text -s :message-info "foo When I run :set-cmd-text -s :message-info "foo
@ -342,7 +342,7 @@ Feature: Various utility commands.
Scenario: Running :pyeval with --quiet Scenario: Running :pyeval with --quiet
When I run :debug-pyeval --quiet 1+1 When I run :debug-pyeval --quiet 1+1
Then "pyeval output: 2" should be logged Then "pyeval output: 2" should be logged
## https://github.com/The-Compiler/qutebrowser/issues/504 ## https://github.com/The-Compiler/qutebrowser/issues/504
Scenario: Focusing download widget via Tab Scenario: Focusing download widget via Tab