From 277ecc9ea7110b79ea0d6c0e25804ea2b218287f Mon Sep 17 00:00:00 2001 From: hut Date: Sun, 10 Jan 2010 22:54:04 +0100 Subject: added chmod command --- TODO | 2 +- ranger/commands.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) 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 + + 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 -- cgit 1.4.1-2-gfad0