diff options
author | nfnty <git@nfnty.se> | 2017-02-08 23:55:27 +0100 |
---|---|---|
committer | nfnty <git@nfnty.se> | 2017-02-08 23:55:27 +0100 |
commit | c377b4814a5560a6fc34c5e5a5df2fe39d289cad (patch) | |
tree | f8682e4b8a2e42cdfb039cddbf59c6f08b2d318b | |
parent | 3fa65ae8bb8cca86742a4f4bf2980a9827aac748 (diff) | |
download | ranger-c377b4814a5560a6fc34c5e5a5df2fe39d289cad.tar.gz |
api.commands.CommandContainer.get_command: Inverse `abbrev`
-rw-r--r-- | ranger/api/commands.py | 19 | ||||
-rw-r--r-- | ranger/core/actions.py | 2 | ||||
-rw-r--r-- | ranger/gui/widgets/console.py | 2 |
3 files changed, 11 insertions, 12 deletions
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)) diff --git a/ranger/core/actions.py b/ranger/core/actions.py index 8bb66a62..703577d3 100644 --- a/ranger/core/actions.py +++ b/ranger/core/actions.py @@ -222,7 +222,7 @@ class Actions( # pylint: disable=too-many-instance-attributes,too-many-public-m Execute a command for the console """ command_name = string.lstrip().split()[0] - cmd_class = self.commands.get_command(command_name, abbrev=False) + cmd_class = self.commands.get_command(command_name) if cmd_class is None: self.notify("Command not found: `%s'" % command_name, bad=True) return diff --git a/ranger/gui/widgets/console.py b/ranger/gui/widgets/console.py index b3fa7151..cc595230 100644 --- a/ranger/gui/widgets/console.py +++ b/ranger/gui/widgets/console.py @@ -450,7 +450,7 @@ class Console(Widget): # pylint: disable=too-many-instance-attributes,too-many- return command_class(self.line) def get_cmd_class(self): - return self.fm.commands.get_command(self.line.split()[0]) + return self.fm.commands.get_command(self.line.split()[0], abbrev=True) def _get_tab(self, tabnum): if ' ' in self.line: |