summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--ranger/api/commands.py65
1 files changed, 23 insertions, 42 deletions
diff --git a/ranger/api/commands.py b/ranger/api/commands.py
index d6c02aaa..b7497b61 100644
--- a/ranger/api/commands.py
+++ b/ranger/api/commands.py
@@ -7,7 +7,6 @@ from __future__ import (absolute_import, division, print_function)
 
 import os
 import re
-import inspect
 # COMPAT pylint: disable=unused-import
 from collections import deque  # NOQA
 from ranger.api import LinemodeBase, hook_init, hook_ready, register_linemode  # NOQA
@@ -20,7 +19,11 @@ from ranger.ext.lazy_property import lazy_property
 _SETTINGS_RE = re.compile(r'^\s*([^\s]+?)=(.*)$')
 
 
-class CommandContainer(object):
+def _alias_line(full_command, line):
+    return full_command + ''.join(re.split(r'(\s+)', line)[1:])
+
+
+class CommandContainer(FileManagerAware):
 
     def __init__(self):
         self.commands = {}
@@ -29,12 +32,24 @@ class CommandContainer(object):
         return self.commands[key]
 
     def alias(self, name, full_command):
-        cmd = type(name, (AliasCommand, ), dict())
-        cmd.based_function = name
-        cmd.function_name = name
-        cmd.object_name = name
-        cmd.full_command = full_command
-        self.commands[name] = cmd
+        cmd_name = full_command.split()[0]
+        try:
+            cmd = self.get_command(cmd_name)
+        except KeyError:
+            self.fm.notify('alias failed: No such command: {0}'.format(cmd_name), bad=True)
+            return None
+
+        class CommandAlias(cmd):   # pylint: disable=too-few-public-methods
+            def __init__(self, line, *args, **kwargs):
+                super(CommandAlias, self).__init__(
+                    _alias_line(self.full_command, line), *args, **kwargs)
+
+        cmd_alias = type(name, (CommandAlias, ), dict(full_command=full_command))
+        if issubclass(cmd_alias, FunctionCommand):
+            cmd_alias.based_function = name
+            cmd_alias.object_name = name
+            cmd_alias.function_name = name
+        self.commands[name] = cmd_alias
 
     def load_commands_from_module(self, module):
         for var in vars(module).values():
@@ -420,40 +435,6 @@ class FunctionCommand(Command):
                 )
 
 
-class AliasCommand(Command):
-    based_function = None
-    object_name = ""
-    function_name = "unknown"
-    full_command = ""
-
-    def execute(self):
-        return self._make_cmd().execute()
-
-    def quick(self):
-        return self._make_cmd().quick()
-
-    def tab(self, tabnum):
-        cmd = self._make_cmd()
-        if self.fm.py3:
-            args = inspect.signature(cmd.tab).parameters  # pylint: disable=no-member
-        else:
-            args = inspect.getargspec(cmd.tab).args  # pylint: disable=deprecated-method
-        return cmd.tab(tabnum) if 'tabnum' in args else cmd.tab()
-
-    def cancel(self):
-        return self._make_cmd().cancel()
-
-    def _make_cmd(self):
-        cmd_class = self.fm.commands.get_command(self.full_command.split()[0])
-        cmd = cmd_class(self.full_command + ' ' + self.rest(1))
-        cmd.quickly_executed = self.quickly_executed
-        cmd.quantifier = self.quantifier
-        cmd.escape_macros_for_shell = self.escape_macros_for_shell
-        cmd.resolve_macros = self.resolve_macros
-        cmd.allow_abbrev = self.allow_abbrev
-        return cmd
-
-
 if __name__ == '__main__':
     import doctest
     doctest.testmod()
0-01-05 03:00:46 +0100 committer hut <hut@lavabit.com> 2010-01-05 03:00:46 +0100 help: implemented help framework, started writing' href='/akspecs/ranger/commit/TODO?h=v1.9.0b3&id=4b826595915c221f12a4ebe187e990cc7a08f7f2'>4b826595 ^
ab65b353 ^

752378e0 ^
4be8b401 ^



d955e3f0 ^
75013dc7 ^
67bb838c ^
a808a661 ^
bba8d293 ^
ab65b353 ^

6f43de0a ^




fca1fc4f ^
ab65b353 ^

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