summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2011-10-03 06:20:43 +0200
committerhut <hut@lavabit.com>2011-10-03 06:20:43 +0200
commit9c4f3cc87b9c15999cb07730caf9657a71b96d0c (patch)
tree6b1c5ab834aa9e7436e192cc229bf502c0f667c0
parent4bea11d661ee302257966bc9fc60c712b72f4e7d (diff)
downloadranger-9c4f3cc87b9c15999cb07730caf9657a71b96d0c.tar.gz
defaults.commands: added alias command, overhauled alias system
-rw-r--r--ranger/api/commands.py15
-rw-r--r--ranger/core/helper.py2
-rw-r--r--ranger/defaults/commands.py15
-rw-r--r--ranger/defaults/rc.conf8
4 files changed, 24 insertions, 16 deletions
diff --git a/ranger/api/commands.py b/ranger/api/commands.py
index a22fd0b3..093e93da 100644
--- a/ranger/api/commands.py
+++ b/ranger/api/commands.py
@@ -21,20 +21,20 @@ from ranger.core.shared import FileManagerAware
 from ranger.ext.lazy_property import lazy_property
 from ranger.ext.command_parser import LazyParser as parse
 
-# A dummy that allows the generation of docstrings in ranger.defaults.commands
-def alias(*_):
-	pass
+def alias(*_): pass # COMPAT
 
 class CommandContainer(object):
 	def __init__(self):
-		self.aliases = {}
 		self.commands = {}
 
 	def __getitem__(self, key):
 		return self.commands[key]
 
 	def alias(self, new, old):
-		self.aliases[new] = old
+		try:
+			self.commands[new] = self.commands[old]
+		except:
+			pass
 
 	def load_commands_from_module(self, module):
 		for varname, var in vars(module).items():
@@ -47,11 +47,6 @@ class CommandContainer(object):
 						self.commands[varname] = var
 			except TypeError:
 				pass
-		for new, old in self.aliases.items():
-			try:
-				self.commands[new] = self.commands[old]
-			except:
-				pass
 
 	def load_commands_from_object(self, obj, filtr):
 		for attribute_name in dir(obj):
diff --git a/ranger/core/helper.py b/ranger/core/helper.py
index 090a475a..9a403a15 100644
--- a/ranger/core/helper.py
+++ b/ranger/core/helper.py
@@ -89,7 +89,6 @@ def load_settings(fm, clean):
 		exclude = ['settings']
 		include = [name for name in dir(Actions) if name not in exclude]
 		comcont.load_commands_from_object(fm, include)
-		ranger.api.commands.alias = comcont.alias
 		try:
 			import commands
 			comcont.load_commands_from_module(commands)
@@ -155,7 +154,6 @@ def load_settings(fm, clean):
 		allow_access_to_confdir(ranger.arg.confdir, False)
 	else:
 		comcont = ranger.api.commands.CommandContainer()
-		ranger.api.commands.alias = comcont.alias
 		from ranger.defaults import commands, apps
 		comcont = ranger.api.commands.CommandContainer()
 		exclude = ['settings']
diff --git a/ranger/defaults/commands.py b/ranger/defaults/commands.py
index 60e3279d..a9a232b9 100644
--- a/ranger/defaults/commands.py
+++ b/ranger/defaults/commands.py
@@ -59,10 +59,17 @@ from ranger.api.commands import *
 from ranger.ext.get_executables import get_executables
 from ranger.core.runner import ALLOWED_FLAGS
 
-alias('e', 'edit')
-alias('q', 'quit')
-alias('q!', 'quitall')
-alias('qall', 'quitall')
+class alias(Command):
+	"""
+	:alias <newcommand> <oldcommand>
+
+	Copies the oldcommand as newcommand.
+	"""
+	def execute(self):
+		if not self.arg(1) or not self.arg(2):
+			self.fm.notify('Syntax: alias <newcommand> <oldcommand>', bad=True)
+		else:
+			self.fm.commands.alias(self.arg(1), self.arg(2))
 
 class cd(Command):
 	"""
diff --git a/ranger/defaults/rc.conf b/ranger/defaults/rc.conf
index 9ba2ed8f..ecd64501 100644
--- a/ranger/defaults/rc.conf
+++ b/ranger/defaults/rc.conf
@@ -17,6 +17,14 @@
 # on the UI such as :delete or :mark.
 # ===================================================================
 
+# ===================================================================
+# == Command Aliases in the Console
+# ===================================================================
+
+alias e    edit
+alias q    quit
+alias q!   quitall
+alias qall quitall
 
 # ===================================================================
 # == Define keys for the browser