Add command aliases

This commit is contained in:
Florian Bruhin 2014-02-21 20:19:01 +01:00
parent 31ffab3386
commit b8b0d81ab3
2 changed files with 14 additions and 1 deletions

View File

@ -148,11 +148,12 @@ class CommandParser(QObject):
self._cmd = None
self._args = []
def _parse(self, text):
def _parse(self, text, aliases=True):
"""Split the commandline text into command and arguments.
Args:
text: Text to parse.
aliases: Whether to handle aliases.
Raise:
NoSuchCommandError if a command wasn't found.
@ -162,6 +163,13 @@ class CommandParser(QObject):
if not parts:
raise NoSuchCommandError("No command given")
cmdstr = parts[0]
if aliases:
try:
alias = config.config.get('aliases', cmdstr)
except config.NoOptionError:
pass
else:
return self._parse(alias, aliases=False)
try:
cmd = cmd_dict[cmdstr]
except KeyError:

View File

@ -121,6 +121,11 @@ PP = tabpaste sel
@Ctrl-D@ = scroll_page 0 0.5
@Ctrl-U@ = scroll_page 0 -0.5
[aliases]
# Here you can add aliases for commands. By default, no aliases are defined.
# Example which adds a new command :qtb to open qutebrowsers website:
# qtb = open http://www.qutebrowser.org/
[colors]
# Colors used in the UI. A value can be in one of the following format:
# - #RGB/#RRGGBB/#RRRGGGBBB/#RRRRGGGGBBBB