Another copy of my dotfiles. Because I don't completely trust GitHub.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.4 KiB

4 years ago
4 years ago
4 years ago
  1. import os
  2. from ranger.api.commands import *
  3. from ranger.core.loader import CommandLoader
  4. class compress(Command):
  5. def execute(self):
  6. """ Compress marked files to current directory """
  7. cwd = self.fm.thisdir
  8. marked_files = cwd.get_selection()
  9. if not marked_files:
  10. return
  11. def refresh(_):
  12. cwd = self.fm.get_directory(original_path)
  13. cwd.load_content()
  14. original_path = cwd.path
  15. # Parsing arguments line
  16. parts = self.line.strip().split()
  17. if len(parts) > 1:
  18. au_flags = [' '.join(parts[1:])]
  19. else:
  20. au_flags = [os.path.basename(self.fm.thisdir.path) + '.tar.gz']
  21. # Making description line
  22. files_num = len(marked_files)
  23. files_num_str = str(files_num) + ' objects' if files_num > 1 else '1 object'
  24. descr = "Compressing " + files_num_str + " -> " + os.path.basename(au_flags[0])
  25. # Creating archive
  26. obj = CommandLoader(args=['apack'] + au_flags + \
  27. [os.path.relpath(f.path, cwd.path) for f in marked_files], descr=descr, read=True)
  28. obj.signal_bind('after', refresh)
  29. self.fm.loader.add(obj)
  30. def tab(self, tabnum):
  31. """ Complete with current folder name """
  32. extension = ['.zip', '.tar.gz', '.rar', '.7z']
  33. return ['compress ' + os.path.basename(self.fm.thisdir.path) + ext for ext in extension]