Allow {url:pretty} variable in commands
This commit is contained in:
parent
5c97ec1659
commit
c7534bd4a3
@ -33,24 +33,33 @@ ParseResult = collections.namedtuple('ParseResult', ['cmd', 'args', 'cmdline',
|
|||||||
'count'])
|
'count'])
|
||||||
|
|
||||||
|
|
||||||
def replace_variables(win_id, arglist):
|
def _current_url(tabbed_browser):
|
||||||
"""Utility function to replace variables like {url} in a list of args."""
|
"""Convenience method to get the current url."""
|
||||||
args = []
|
|
||||||
tabbed_browser = objreg.get('tabbed-browser', scope='window',
|
|
||||||
window=win_id)
|
|
||||||
if '{url}' in arglist:
|
|
||||||
try:
|
try:
|
||||||
url = tabbed_browser.current_url().toString(QUrl.FullyEncoded |
|
return tabbed_browser.current_url()
|
||||||
QUrl.RemovePassword)
|
|
||||||
except qtutils.QtValueError as e:
|
except qtutils.QtValueError as e:
|
||||||
msg = "Current URL is invalid"
|
msg = "Current URL is invalid"
|
||||||
if e.reason:
|
if e.reason:
|
||||||
msg += " ({})".format(e.reason)
|
msg += " ({})".format(e.reason)
|
||||||
msg += "!"
|
msg += "!"
|
||||||
raise cmdexc.CommandError(msg)
|
raise cmdexc.CommandError(msg)
|
||||||
|
|
||||||
|
|
||||||
|
def replace_variables(win_id, arglist):
|
||||||
|
"""Utility function to replace variables like {url} in a list of args."""
|
||||||
|
args = []
|
||||||
|
tabbed_browser = objreg.get('tabbed-browser', scope='window',
|
||||||
|
window=win_id)
|
||||||
|
if '{url}' in arglist:
|
||||||
|
url = _current_url(tabbed_browser).toString(QUrl.FullyEncoded |
|
||||||
|
QUrl.RemovePassword)
|
||||||
|
if '{url:pretty}' in arglist:
|
||||||
|
pretty_url = _current_url(tabbed_browser).toString(QUrl.RemovePassword)
|
||||||
for arg in arglist:
|
for arg in arglist:
|
||||||
if arg == '{url}':
|
if arg == '{url}':
|
||||||
args.append(url)
|
args.append(url)
|
||||||
|
elif arg == '{url:pretty}':
|
||||||
|
args.append(pretty_url)
|
||||||
else:
|
else:
|
||||||
args.append(arg)
|
args.append(arg)
|
||||||
return args
|
return args
|
||||||
|
Loading…
Reference in New Issue
Block a user