diff --git a/ranger/.config/ranger/commands.py b/ranger/.config/ranger/commands.py index 97b7909..bd79306 100644 --- a/ranger/.config/ranger/commands.py +++ b/ranger/.config/ranger/commands.py @@ -60,3 +60,37 @@ class my_edit(Command): # This is a generic tab-completion function that iterates through the # content of the current directory. return self._tab_directory_content() + +import os +from ranger.core.loader import CommandLoader + +class compress(Command): + def execute(self): + """ Compress marked files to current directory """ + cwd = self.fm.thisdir + marked_files = cwd.get_selection() + + if not marked_files: + return + + def refresh(_): + cwd = self.fm.get_directory(original_path) + cwd.load_content() + + original_path = cwd.path + parts = self.line.split() + au_flags = parts[1:] + + descr = "compressing files in: " + os.path.basename(parts[1]) + obj = CommandLoader(args=['apack'] + au_flags + \ + [os.path.relpath(f.path, cwd.path) for f in marked_files], descr=descr, read=True) + + obj.signal_bind('after', refresh) + self.fm.loader.add(obj) + + def tab(self, tabnum): + """ Complete with current folder name """ + + extension = ['.zip', '.tar.gz', '.rar', '.7z'] + return ['compress ' + os.path.basename(self.fm.thisdir.path) + ext for ext in extension] +