mirror of https://github.com/Flinner/dots.git
feat: add `:compress` command to ranger
This commit is contained in:
parent
84bb3f4c1c
commit
2763a2059c
|
@ -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]
|
||||
|
||||
|
|
Loading…
Reference in New Issue