diff options
author | hut <hut@lavabit.com> | 2010-01-10 22:54:04 +0100 |
---|---|---|
committer | hut <hut@lavabit.com> | 2010-01-10 22:54:04 +0100 |
commit | 277ecc9ea7110b79ea0d6c0e25804ea2b218287f (patch) | |
tree | b487d5c2b366ee209ec58cddaaafb5a60a4f3671 | |
parent | 8757f653918eb6ccfc5ec6715957e6cd04a2ff3f (diff) | |
download | ranger-277ecc9ea7110b79ea0d6c0e25804ea2b218287f.tar.gz |
added chmod command
-rw-r--r-- | TODO | 2 | ||||
-rw-r--r-- | ranger/commands.py | 31 |
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> |