about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2009-12-27 00:53:38 +0100
committerhut <hut@lavabit.com>2009-12-27 00:53:38 +0100
commit2efce5400bed218ca603444d179bee503fa6d9f5 (patch)
treed4b01504b90620582676894b77ef49dca92c62ce
parent0da7b3961de437415753383a5c2b7efaafcc4586 (diff)
downloadranger-2efce5400bed218ca603444d179bee503fa6d9f5.tar.gz
added rename command
-rw-r--r--ranger/actions.py11
-rw-r--r--ranger/commands.py6
-rw-r--r--ranger/defaults/keys.py7
3 files changed, 24 insertions, 0 deletions
diff --git a/ranger/actions.py b/ranger/actions.py
index d500f18a..31f4cb41 100644
--- a/ranger/actions.py
+++ b/ranger/actions.py
@@ -283,6 +283,17 @@ class Actions(EnvironmentAware, SettingsAware):
 			os.mkdir(os.path.join(self.env.pwd.path, name))
 		except OSError as err:
 			self.notify(str(err), bad=True)
+
+	
+	def rename(self, src, dest):
+		if hasattr(src, 'path'):
+			src = src.path
+
+		try:
+			os.rename(src, dest)
+		except OSError as err:
+			self.notify(str(err), bad=True)
+
 	
 	def notify(self, text, duration=4, bad=False):
 		try:
diff --git a/ranger/commands.py b/ranger/commands.py
index a3cc131e..68b9c574 100644
--- a/ranger/commands.py
+++ b/ranger/commands.py
@@ -161,6 +161,12 @@ class mkdir(Command):
 			pass
 
 
+class rename(Command):
+	def execute(self):
+		line = parse(self.line)
+		self.fm.rename(self.fm.env.cf, line.rest(1))
+	
+
 # -------------------------------- rest
 
 by_name = {}
diff --git a/ranger/defaults/keys.py b/ranger/defaults/keys.py
index 9837d2a2..88f570df 100644
--- a/ranger/defaults/keys.py
+++ b/ranger/defaults/keys.py
@@ -72,6 +72,13 @@ def initialize_commands(command_list):
 			fm.sort(reverse=not fm.settings.reverse))
 	command_list.hint(sort_hint, 'o', 'O')
 
+	def edit_name(fm, n):
+		cf = fm.env.cf
+		if cf:
+			fm.open_console(cmode.COMMAND, 'rename ' + cf.basename)
+
+	bind('A', edit_name)
+	bind('cw', do('open_console', cmode.COMMAND, 'rename '))
 	bind('cd', do('open_console', cmode.COMMAND, 'cd '))
 	bind('f', do('open_console', cmode.COMMAND_QUICK, 'find '))