From c7534bd4a3b2e65da9fa901794b01014e60c386a Mon Sep 17 00:00:00 2001 From: Panagiotis Ktistakis Date: Tue, 19 Apr 2016 12:52:47 +0300 Subject: [PATCH] Allow {url:pretty} variable in commands --- qutebrowser/commands/runners.py | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/qutebrowser/commands/runners.py b/qutebrowser/commands/runners.py index fbd7b1b22..bca05d80f 100644 --- a/qutebrowser/commands/runners.py +++ b/qutebrowser/commands/runners.py @@ -33,24 +33,33 @@ ParseResult = collections.namedtuple('ParseResult', ['cmd', 'args', 'cmdline', 'count']) +def _current_url(tabbed_browser): + """Convenience method to get the current url.""" + try: + return tabbed_browser.current_url() + except qtutils.QtValueError as e: + msg = "Current URL is invalid" + if e.reason: + msg += " ({})".format(e.reason) + 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: - 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) + 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: if arg == '{url}': args.append(url) + elif arg == '{url:pretty}': + args.append(pretty_url) else: args.append(arg) return args