diff options
author | hut <hut@lavabit.com> | 2010-01-19 21:18:53 +0100 |
---|---|---|
committer | hut <hut@lavabit.com> | 2010-01-19 21:18:53 +0100 |
commit | af6658b377d145529e0b9304247ed3b9b6e40856 (patch) | |
tree | 2c283f89f634e9bfb841a10d8e2c49a137846e9d /ranger | |
parent | 33cb688a37d07e0cc8c4053be46ac3605235468e (diff) | |
download | ranger-af6658b377d145529e0b9304247ed3b9b6e40856.tar.gz |
implemented #48: abbreviate commands
Diffstat (limited to 'ranger')
-rw-r--r-- | ranger/commands.py | 16 | ||||
-rw-r--r-- | ranger/gui/widgets/console.py | 6 |
2 files changed, 19 insertions, 3 deletions
diff --git a/ranger/commands.py b/ranger/commands.py index ea8e41f4..0cfe78b6 100644 --- a/ranger/commands.py +++ b/ranger/commands.py @@ -404,11 +404,23 @@ del varname del var def alias(**kw): + """Create an alias for commands, eg: alias(quit=exit)""" for key, value in kw.items(): by_name[key] = value -alias(q=quit) -alias(e=edit) +def get_command(name, abbrev=True): + if abbrev: + lst = [cls for cmd, cls in by_name.items() if cmd.startswith(name)] + if len(lst) == 0: + raise KeyError + if len(lst) == 1: + return lst[0] + raise ValueError("Ambiguous command") + else: + try: + return by_name[name] + except KeyError: + return None def command_generator(start): return (cmd + ' ' for cmd in by_name if cmd.startswith(start)) diff --git a/ranger/gui/widgets/console.py b/ranger/gui/widgets/console.py index 0da0480b..5c888da5 100644 --- a/ranger/gui/widgets/console.py +++ b/ranger/gui/widgets/console.py @@ -292,8 +292,12 @@ class CommandConsole(ConsoleWithTab): return None try: - return commands.by_name[command_name] + return commands.get_command(command_name) except KeyError: + self.fm.notify("Invalid command! Press ? for help.", bad=True) + return None + except ValueError as e: + self.fm.notify(e) return None def _get_tab(self): |