summary refs log tree commit diff stats
path: root/ranger
diff options
context:
space:
mode:
authorM Rawash <mrawash@gmail.com>2012-01-27 00:14:55 +0200
committerM Rawash <mrawash@gmail.com>2012-01-27 00:14:55 +0200
commit47c2cf6920324da597cf969329c0abb59591c9ca (patch)
tree5c0dff1fc4cac192fdd373277e6b565977d2cdb0 /ranger
parent9e146c8272e25b98d0f196bc34ac1725f894863a (diff)
downloadranger-47c2cf6920324da597cf969329c0abb59591c9ca.tar.gz
new :relink command
Diffstat (limited to 'ranger')
-rw-r--r--ranger/defaults/commands.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/ranger/defaults/commands.py b/ranger/defaults/commands.py
index c9729999..d1f4cf16 100644
--- a/ranger/defaults/commands.py
+++ b/ranger/defaults/commands.py
@@ -818,6 +818,45 @@ class bulkrename(Command):
 		cmdfile.close()
 
 
+class relink(Command):
+	"""
+	:relink <newpath>
+
+	Changes the linked path of the currently highlighted symlink to <newpath>
+	"""
+
+	def execute(self):
+		from ranger.fsobject import File
+
+		new_path = self.rest(1)
+		cf = self.fm.env.cf
+
+		if not new_path:
+			return self.fm.notify('Syntax: relink <newpath>', bad=True)
+
+		if not cf.is_link:
+			return self.fm.notify('%s is not a symlink!' % cf.basename, bad=True)
+			
+		if new_path == os.readlink(cf.path):
+			return
+		
+		try:
+			os.remove(cf.path)
+			os.symlink(new_path, cf.path)
+		except OSError as err:
+			self.fm.notify(err)
+
+		self.fm.reset()
+		self.fm.env.cwd.pointed_obj = cf
+		self.fm.env.cf = cf
+
+	def tab(self):
+		if not self.rest(1):
+			return self.line+os.readlink(self.fm.env.cf.path)
+		else:
+			return self._tab_directory_content()
+
+
 class help_(Command):
 	"""
 	:help