about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--TODO2
-rw-r--r--ranger/commands.py31
2 files changed, 32 insertions, 1 deletions
diff --git a/TODO b/TODO
index 77817b43..95bf2984 100644
--- a/TODO
+++ b/TODO
@@ -22,7 +22,7 @@ General
    (X) #16  10/01/01  list of bookmarks
    (X) #21  10/01/01  write help!
    ( ) #22  10/01/03  add getopt options to change flags/mode
-   ( ) #29  10/01/06  add chmod command
+   (X) #29  10/01/06  add chmod command
    ( ) #30  10/01/06  add a way to create symlinks
    ( ) #32  10/01/08  place the (hidden) cursor to a meaningful position
    ( ) #34  10/01/09  display free disk space
diff --git a/ranger/commands.py b/ranger/commands.py
index 7fb3a62c..8d71b3eb 100644
--- a/ranger/commands.py
+++ b/ranger/commands.py
@@ -280,6 +280,37 @@ class rename(Command):
 		return self._tab_directory_content()
 
 
+class chmod(Command):
+	"""
+	:chmod <octal number>
+
+	Sets the permissions of the selection to the octal number.
+	"""
+	def execute(self):
+		line = parse(self.line)
+		mode = line.rest(1)
+
+		try:
+			mode = int(mode, 8)
+			if mode < 0 or mode > 511:
+				raise ValueError
+		except ValueError:
+			self.fm.notify("Need an octal number between 0 and 777!", bad=True)
+			return
+
+		for file in self.fm.env.get_selection():
+			try:
+				os.chmod(file.path, mode)
+			except Exception as ex:
+				self.fm.notify(str(ex), bad=True)
+
+		try:
+			# reloading directory.  maybe its better to reload the selected
+			# files only.
+			self.fm.env.pwd.load_content()
+		except:
+			pass
+
 class filter(Command):
 	"""
 	:filter <string>