summary refs log tree commit diff stats
diff options
context:
space:
mode:
authornfnty <git@nfnty.se>2017-02-08 23:55:27 +0100
committernfnty <git@nfnty.se>2017-02-08 23:55:27 +0100
commitc377b4814a5560a6fc34c5e5a5df2fe39d289cad (patch)
treef8682e4b8a2e42cdfb039cddbf59c6f08b2d318b
parent3fa65ae8bb8cca86742a4f4bf2980a9827aac748 (diff)
downloadranger-c377b4814a5560a6fc34c5e5a5df2fe39d289cad.tar.gz
api.commands.CommandContainer.get_command: Inverse `abbrev`
-rw-r--r--ranger/api/commands.py19
-rw-r--r--ranger/core/actions.py2
-rw-r--r--ranger/gui/widgets/console.py2
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:
/a> ^
08a0eed6 ^







ac07e589 ^


08a0eed6 ^




a220427e ^







c762564b ^
9a7e1a0f ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99