Add aliases for commands
This commit is contained in:
parent
1373b4dab2
commit
5c8043a275
@ -8,6 +8,8 @@ A command class can set the following properties:
|
|||||||
nargs -- Number of arguments. Either a number, '?' (0 or 1), '+' (1 or
|
nargs -- Number of arguments. Either a number, '?' (0 or 1), '+' (1 or
|
||||||
more), or '*' (any). Default: 0
|
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
|
split_args -- If arguments should be split or not. Default: True
|
||||||
|
|
||||||
count -- If the command supports a count. Default: False
|
count -- If the command supports a count. Default: False
|
||||||
@ -32,6 +34,7 @@ class TabPrev(Command):
|
|||||||
nargs = 0
|
nargs = 0
|
||||||
|
|
||||||
class Quit(Command):
|
class Quit(Command):
|
||||||
|
name = ['quit', 'q']
|
||||||
nargs = 0
|
nargs = 0
|
||||||
|
|
||||||
class Reload(Command):
|
class Reload(Command):
|
||||||
|
@ -20,7 +20,12 @@ def register_all():
|
|||||||
qutebrowser.commands.commands, (lambda o: inspect.isclass(o) and
|
qutebrowser.commands.commands, (lambda o: inspect.isclass(o) and
|
||||||
o.__module__ == 'qutebrowser.commands.commands')):
|
o.__module__ == 'qutebrowser.commands.commands')):
|
||||||
obj = cls()
|
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):
|
class CommandParser(QObject):
|
||||||
"""Parser for qutebrowser commandline commands"""
|
"""Parser for qutebrowser commandline commands"""
|
||||||
@ -33,9 +38,6 @@ class CommandParser(QObject):
|
|||||||
"""Parses a command and runs its handler"""
|
"""Parses a command and runs its handler"""
|
||||||
self.text = text
|
self.text = text
|
||||||
parts = self.text.strip().split(maxsplit=1)
|
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]
|
cmdstr = parts[0]
|
||||||
try:
|
try:
|
||||||
cmd = cmd_dict[cmdstr]
|
cmd = cmd_dict[cmdstr]
|
||||||
@ -110,14 +112,18 @@ class Command(QObject):
|
|||||||
args -- Arguments to the command.
|
args -- Arguments to the command.
|
||||||
count -- Command repetition count.
|
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:
|
if args:
|
||||||
dbgout += args
|
dbgout += args
|
||||||
if count is not None:
|
if count is not None:
|
||||||
dbgout.append("(count={})".format(count))
|
dbgout.append("(count={})".format(count))
|
||||||
logging.debug(' '.join(dbgout))
|
logging.debug(' '.join(dbgout))
|
||||||
|
|
||||||
argv = [self.name]
|
argv = [name]
|
||||||
if args is not None:
|
if args is not None:
|
||||||
argv += args
|
argv += args
|
||||||
self.signal.emit((count, argv))
|
self.signal.emit((count, argv))
|
||||||
|
Loading…
Reference in New Issue
Block a user