Merge branch 'better-variables' of https://github.com/blyxxyz/qutebrowser into blyxxyz-better-variables
This commit is contained in:
commit
b6fbd3ce3a
@ -110,6 +110,7 @@ Bind a key to a command.
|
|||||||
==== note
|
==== note
|
||||||
* This command does not split arguments after the last argument and handles quotes literally.
|
* This command does not split arguments after the last argument and handles quotes literally.
|
||||||
* With this command, +;;+ is interpreted literally instead of splitting off a second command.
|
* With this command, +;;+ is interpreted literally instead of splitting off a second command.
|
||||||
|
* This command does not replace variables like +\{url\}+.
|
||||||
|
|
||||||
[[bookmark-add]]
|
[[bookmark-add]]
|
||||||
=== bookmark-add
|
=== bookmark-add
|
||||||
@ -424,6 +425,7 @@ Execute a command after some time.
|
|||||||
==== note
|
==== note
|
||||||
* This command does not split arguments after the last argument and handles quotes literally.
|
* This command does not split arguments after the last argument and handles quotes literally.
|
||||||
* With this command, +;;+ is interpreted literally instead of splitting off a second command.
|
* With this command, +;;+ is interpreted literally instead of splitting off a second command.
|
||||||
|
* This command does not replace variables like +\{url\}+.
|
||||||
|
|
||||||
[[messages]]
|
[[messages]]
|
||||||
=== messages
|
=== messages
|
||||||
@ -591,6 +593,7 @@ Repeat a given command.
|
|||||||
==== note
|
==== note
|
||||||
* This command does not split arguments after the last argument and handles quotes literally.
|
* This command does not split arguments after the last argument and handles quotes literally.
|
||||||
* With this command, +;;+ is interpreted literally instead of splitting off a second command.
|
* With this command, +;;+ is interpreted literally instead of splitting off a second command.
|
||||||
|
* This command does not replace variables like +\{url\}+.
|
||||||
|
|
||||||
[[report]]
|
[[report]]
|
||||||
=== report
|
=== report
|
||||||
|
@ -980,7 +980,7 @@ class CommandDispatcher:
|
|||||||
self._tabbed_browser.setUpdatesEnabled(True)
|
self._tabbed_browser.setUpdatesEnabled(True)
|
||||||
|
|
||||||
@cmdutils.register(instance='command-dispatcher', scope='window',
|
@cmdutils.register(instance='command-dispatcher', scope='window',
|
||||||
maxsplit=0)
|
maxsplit=0, no_replace_variables=True)
|
||||||
def spawn(self, cmdline, userscript=False, verbose=False, detach=False):
|
def spawn(self, cmdline, userscript=False, verbose=False, detach=False):
|
||||||
"""Spawn a command in a shell.
|
"""Spawn a command in a shell.
|
||||||
|
|
||||||
|
@ -81,6 +81,7 @@ class Command:
|
|||||||
no_cmd_split: If true, ';;' to split sub-commands is ignored.
|
no_cmd_split: If true, ';;' to split sub-commands is ignored.
|
||||||
backend: Which backend the command works with (or None if it works with
|
backend: Which backend the command works with (or None if it works with
|
||||||
both)
|
both)
|
||||||
|
no_replace_variables: Don't replace variables like {url}
|
||||||
_qute_args: The saved data from @cmdutils.argument
|
_qute_args: The saved data from @cmdutils.argument
|
||||||
_needs_js: Whether the command needs javascript enabled
|
_needs_js: Whether the command needs javascript enabled
|
||||||
_modes: The modes the command can be executed in.
|
_modes: The modes the command can be executed in.
|
||||||
@ -94,7 +95,7 @@ class Command:
|
|||||||
hide=False, modes=None, not_modes=None, needs_js=False,
|
hide=False, modes=None, not_modes=None, needs_js=False,
|
||||||
debug=False, ignore_args=False, deprecated=False,
|
debug=False, ignore_args=False, deprecated=False,
|
||||||
no_cmd_split=False, star_args_optional=False, scope='global',
|
no_cmd_split=False, star_args_optional=False, scope='global',
|
||||||
backend=None):
|
backend=None, no_replace_variables=False):
|
||||||
# I really don't know how to solve this in a better way, I tried.
|
# I really don't know how to solve this in a better way, I tried.
|
||||||
# pylint: disable=too-many-locals
|
# pylint: disable=too-many-locals
|
||||||
if modes is not None and not_modes is not None:
|
if modes is not None and not_modes is not None:
|
||||||
@ -126,6 +127,7 @@ class Command:
|
|||||||
self.handler = handler
|
self.handler = handler
|
||||||
self.no_cmd_split = no_cmd_split
|
self.no_cmd_split = no_cmd_split
|
||||||
self.backend = backend
|
self.backend = backend
|
||||||
|
self.no_replace_variables = no_replace_variables
|
||||||
|
|
||||||
self.docparser = docutils.DocstringParser(handler)
|
self.docparser = docutils.DocstringParser(handler)
|
||||||
self.parser = argparser.ArgumentParser(
|
self.parser = argparser.ArgumentParser(
|
||||||
|
@ -52,16 +52,16 @@ def replace_variables(win_id, arglist):
|
|||||||
args = []
|
args = []
|
||||||
tabbed_browser = objreg.get('tabbed-browser', scope='window',
|
tabbed_browser = objreg.get('tabbed-browser', scope='window',
|
||||||
window=win_id)
|
window=win_id)
|
||||||
if '{url}' in arglist:
|
if any('{url}' in arg for arg in arglist):
|
||||||
url = _current_url(tabbed_browser).toString(QUrl.FullyEncoded |
|
url = _current_url(tabbed_browser).toString(QUrl.FullyEncoded |
|
||||||
QUrl.RemovePassword)
|
QUrl.RemovePassword)
|
||||||
if '{url:pretty}' in arglist:
|
if any('{url:pretty}' in arg for arg in arglist):
|
||||||
pretty_url = _current_url(tabbed_browser).toString(QUrl.RemovePassword)
|
pretty_url = _current_url(tabbed_browser).toString(QUrl.RemovePassword)
|
||||||
for arg in arglist:
|
for arg in arglist:
|
||||||
if arg == '{url}':
|
if '{url}' in arg:
|
||||||
args.append(url)
|
args.append(arg.replace('{url}', url))
|
||||||
elif arg == '{url:pretty}':
|
elif '{url:pretty}' in arg:
|
||||||
args.append(pretty_url)
|
args.append(arg.replace('{url:pretty}', pretty_url))
|
||||||
else:
|
else:
|
||||||
args.append(arg)
|
args.append(arg)
|
||||||
return args
|
return args
|
||||||
@ -279,7 +279,10 @@ class CommandRunner(QObject):
|
|||||||
window=self._win_id)
|
window=self._win_id)
|
||||||
cur_mode = mode_manager.mode
|
cur_mode = mode_manager.mode
|
||||||
|
|
||||||
args = replace_variables(self._win_id, result.args)
|
if result.cmd.no_replace_variables:
|
||||||
|
args = result.args
|
||||||
|
else:
|
||||||
|
args = replace_variables(self._win_id, result.args)
|
||||||
if count is not None:
|
if count is not None:
|
||||||
if result.count is not None:
|
if result.count is not None:
|
||||||
raise cmdexc.CommandMetaError("Got count via command and "
|
raise cmdexc.CommandMetaError("Got count via command and "
|
||||||
|
@ -150,7 +150,8 @@ class KeyConfigParser(QObject):
|
|||||||
data = str(self)
|
data = str(self)
|
||||||
f.write(data)
|
f.write(data)
|
||||||
|
|
||||||
@cmdutils.register(instance='key-config', maxsplit=1, no_cmd_split=True)
|
@cmdutils.register(instance='key-config', maxsplit=1, no_cmd_split=True,
|
||||||
|
no_replace_variables=True)
|
||||||
@cmdutils.argument('win_id', win_id=True)
|
@cmdutils.argument('win_id', win_id=True)
|
||||||
@cmdutils.argument('command', completion=usertypes.Completion.command)
|
@cmdutils.argument('command', completion=usertypes.Completion.command)
|
||||||
def bind(self, key, win_id, command=None, *, mode='normal', force=False):
|
def bind(self, key, win_id, command=None, *, mode='normal', force=False):
|
||||||
|
@ -23,8 +23,8 @@ from PyQt5.QtCore import pyqtSignal, pyqtSlot, Qt, 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, runners
|
from qutebrowser.commands import cmdexc, cmdutils
|
||||||
from qutebrowser.misc import cmdhistory, split
|
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
|
from qutebrowser.utils import usertypes, log, objreg
|
||||||
|
|
||||||
@ -108,10 +108,6 @@ 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.
|
||||||
"""
|
"""
|
||||||
args = split.simple_split(text)
|
|
||||||
args = runners.replace_variables(self._win_id, args)
|
|
||||||
text = ' '.join(args)
|
|
||||||
|
|
||||||
if space:
|
if space:
|
||||||
text += ' '
|
text += ' '
|
||||||
if append:
|
if append:
|
||||||
|
@ -39,7 +39,7 @@ from PyQt5.QtCore import QUrl
|
|||||||
from PyQt5.QtWidgets import QApplication # pylint: disable=unused-import
|
from PyQt5.QtWidgets import QApplication # pylint: disable=unused-import
|
||||||
|
|
||||||
|
|
||||||
@cmdutils.register(maxsplit=1, no_cmd_split=True)
|
@cmdutils.register(maxsplit=1, no_cmd_split=True, no_replace_variables=True)
|
||||||
@cmdutils.argument('win_id', win_id=True)
|
@cmdutils.argument('win_id', win_id=True)
|
||||||
def later(ms: int, command, win_id):
|
def later(ms: int, command, win_id):
|
||||||
"""Execute a command after some time.
|
"""Execute a command after some time.
|
||||||
@ -69,7 +69,7 @@ def later(ms: int, command, win_id):
|
|||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
@cmdutils.register(maxsplit=1, no_cmd_split=True)
|
@cmdutils.register(maxsplit=1, no_cmd_split=True, no_replace_variables=True)
|
||||||
@cmdutils.argument('win_id', win_id=True)
|
@cmdutils.argument('win_id', win_id=True)
|
||||||
def repeat(times: int, command, win_id):
|
def repeat(times: int, command, win_id):
|
||||||
"""Repeat a given command.
|
"""Repeat a given command.
|
||||||
|
@ -239,7 +239,8 @@ def _get_command_doc_notes(cmd):
|
|||||||
Yield:
|
Yield:
|
||||||
Strings which should be added to the docs.
|
Strings which should be added to the docs.
|
||||||
"""
|
"""
|
||||||
if cmd.maxsplit is not None or cmd.no_cmd_split:
|
if (cmd.maxsplit is not None or cmd.no_cmd_split or
|
||||||
|
cmd.no_replace_variables and cmd.name != "spawn"):
|
||||||
yield ""
|
yield ""
|
||||||
yield "==== note"
|
yield "==== note"
|
||||||
if cmd.maxsplit is not None:
|
if cmd.maxsplit is not None:
|
||||||
@ -248,6 +249,8 @@ def _get_command_doc_notes(cmd):
|
|||||||
if cmd.no_cmd_split:
|
if cmd.no_cmd_split:
|
||||||
yield ("* With this command, +;;+ is interpreted literally "
|
yield ("* With this command, +;;+ is interpreted literally "
|
||||||
"instead of splitting off a second command.")
|
"instead of splitting off a second command.")
|
||||||
|
if cmd.no_replace_variables and cmd.name != "spawn":
|
||||||
|
yield r"* This command does not replace variables like +\{url\}+."
|
||||||
|
|
||||||
|
|
||||||
def _get_action_metavar(action, nargs=1):
|
def _get_action_metavar(action, nargs=1):
|
||||||
|
Loading…
Reference in New Issue
Block a user