Add aliases for commands

This commit is contained in:
Florian Bruhin 2014-01-20 17:32:04 +01:00
parent 1373b4dab2
commit 5c8043a275
2 changed files with 15 additions and 6 deletions

View File

@ -8,6 +8,8 @@ A command class can set the following properties:
nargs -- Number of arguments. Either a number, '?' (0 or 1), '+' (1 or
more), or '*' (any). Default: 0
name -- The name of the command, or a list of aliases
split_args -- If arguments should be split or not. Default: True
count -- If the command supports a count. Default: False
@ -32,6 +34,7 @@ class TabPrev(Command):
nargs = 0
class Quit(Command):
name = ['quit', 'q']
nargs = 0
class Reload(Command):

View File

@ -20,7 +20,12 @@ def register_all():
qutebrowser.commands.commands, (lambda o: inspect.isclass(o) and
o.__module__ == 'qutebrowser.commands.commands')):
obj = cls()
cmd_dict[obj.name] = obj
if isinstance(obj.name, str):
names = [obj.name]
else:
names = obj.name
for n in names:
cmd_dict[n] = obj
class CommandParser(QObject):
"""Parser for qutebrowser commandline commands"""
@ -33,9 +38,6 @@ class CommandParser(QObject):
"""Parses a command and runs its handler"""
self.text = text
parts = self.text.strip().split(maxsplit=1)
# FIXME maybe we should handle unambigious shorthands for commands
# here? Or at least we should add :q for :quit.
cmdstr = parts[0]
try:
cmd = cmd_dict[cmdstr]
@ -110,14 +112,18 @@ class Command(QObject):
args -- Arguments to the command.
count -- Command repetition count.
"""
dbgout = ["command called:", self.name]
if isinstance(self.name, str):
name = self.name
else:
name = self.name[0]
dbgout = ["command called:", name]
if args:
dbgout += args
if count is not None:
dbgout.append("(count={})".format(count))
logging.debug(' '.join(dbgout))
argv = [self.name]
argv = [name]
if args is not None:
argv += args
self.signal.emit((count, argv))