From c377b4814a5560a6fc34c5e5a5df2fe39d289cad Mon Sep 17 00:00:00 2001 From: nfnty Date: Wed, 8 Feb 2017 23:55:27 +0100 Subject: api.commands.CommandContainer.get_command: Inverse `abbrev` --- ranger/api/commands.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'ranger/api/commands.py') diff --git a/ranger/api/commands.py b/ranger/api/commands.py index b9e0d6e9..24a82d0b 100644 --- a/ranger/api/commands.py +++ b/ranger/api/commands.py @@ -51,12 +51,11 @@ class CommandContainer(FileManagerAware): def alias(self, name, full_command): cmd_name = full_command.split()[0] - try: - cmd = self.get_command(cmd_name) - except KeyError: + cmd_cls = self.get_command(cmd_name) + if cmd_cls is None: self.fm.notify('alias failed: No such command: {0}'.format(cmd_name), bad=True) return None - self.commands[name] = _command_init(command_alias_factory(name, cmd, full_command)) + self.commands[name] = _command_init(command_alias_factory(name, cmd_cls, full_command)) def load_commands_from_module(self, module): for var in vars(module).values(): @@ -74,7 +73,7 @@ class CommandContainer(FileManagerAware): if hasattr(attribute, '__call__'): self.commands[attribute_name] = _command_init(command_function_factory(attribute)) - def get_command(self, name, abbrev=True): + def get_command(self, name, abbrev=False): if abbrev: lst = [cls for cmd, cls in self.commands.items() if cls.allow_abbrev and cmd.startswith(name) or cmd == name] @@ -85,11 +84,11 @@ class CommandContainer(FileManagerAware): if self.commands[name] in lst: return self.commands[name] raise ValueError("Ambiguous command") - else: - try: - return self.commands[name] - except KeyError: - return None + + try: + return self.commands[name] + except KeyError: + return None def command_generator(self, start): return sorted(cmd + ' ' for cmd in self.commands if cmd.startswith(start)) -- cgit 1.4.1-2-gfad0