diff --git a/qutebrowser/commands/runners.py b/qutebrowser/commands/runners.py index d83c00e66..ea4b2ac0f 100644 --- a/qutebrowser/commands/runners.py +++ b/qutebrowser/commands/runners.py @@ -172,6 +172,9 @@ class CommandRunner(QObject): log.commands.debug("Re-parsing with '{}'.".format(new_cmd)) return self.parse(new_cmd, aliases=False, fallback=fallback, keep=keep) + + cmdstr = self._completion_match(cmdstr) + try: cmd = cmdutils.cmd_dict[cmdstr] except KeyError: @@ -196,6 +199,23 @@ class CommandRunner(QObject): cmdline = [cmdstr] + args[:] return ParseResult(cmd=cmd, args=args, cmdline=cmdline, count=count) + def _completion_match(self, cmdstr): + """Replace cmdstr with a matching completion if there's only one match. + + Args: + cmdstr: The string representing the entered command so far + + Return: + cmdstr modified to the matching completion or unmodified + """ + matches = [] + for valid_command in cmdutils.cmd_dict.keys(): + if valid_command.find(cmdstr) == 0: + matches.append(valid_command) + if len(matches) == 1: + cmdstr = matches[0] + return cmdstr + def _split_args(self, cmd, argstr, keep): """Split the arguments from an arg string.