1
0

Update home/.config/ranger/command.py

This commit is contained in:
Jeff Lance 2024-02-22 16:08:21 +01:00
parent 757449795e
commit 34376e32b6

View File

@ -11,76 +11,76 @@ from ranger.core.loader import CommandLoader
from ranger_udisk_menu.mounter import mount from ranger_udisk_menu.mounter import mount
class extract_here(Command): # class extract_here(Command):
def execute(self): # def execute(self):
"""extract selected files to current directory.""" # """extract selected files to current directory."""
cwd = self.fm.thisdir # cwd = self.fm.thisdir
marked_files = tuple(cwd.get_selection()) # marked_files = tuple(cwd.get_selection())
def refresh(_): # def refresh(_):
cwd = self.fm.get_directory(original_path) # cwd = self.fm.get_directory(original_path)
cwd.load_content() # cwd.load_content()
one_file = marked_files[0] # one_file = marked_files[0]
cwd = self.fm.thisdir # cwd = self.fm.thisdir
original_path = cwd.path # original_path = cwd.path
au_flags = ["-x", cwd.path] # au_flags = ["-x", cwd.path]
au_flags += self.line.split()[1:] # au_flags += self.line.split()[1:]
au_flags += ["-e"] # au_flags += ["-e"]
self.fm.copy_buffer.clear() # self.fm.copy_buffer.clear()
self.fm.cut_buffer = False # self.fm.cut_buffer = False
if len(marked_files) == 1: # if len(marked_files) == 1:
descr = "extracting: " + os.path.basename(one_file.path) # descr = "extracting: " + os.path.basename(one_file.path)
else: # else:
descr = "extracting files from: " + os.path.basename(one_file.dirname) # descr = "extracting files from: " + os.path.basename(one_file.dirname)
obj = CommandLoader( # obj = CommandLoader(
args=["aunpack"] + au_flags + [f.path for f in marked_files], # args=["aunpack"] + au_flags + [f.path for f in marked_files],
descr=descr, # descr=descr,
read=True, # read=True,
) # )
obj.signal_bind("after", refresh) # obj.signal_bind("after", refresh)
self.fm.loader.add(obj) # self.fm.loader.add(obj)
class compress(Command): # class compress(Command):
def execute(self): # def execute(self):
"""Compress marked files to current directory""" # """Compress marked files to current directory"""
cwd = self.fm.thisdir # cwd = self.fm.thisdir
marked_files = cwd.get_selection() # marked_files = cwd.get_selection()
if not marked_files: # if not marked_files:
return # return
def refresh(_): # def refresh(_):
cwd = self.fm.get_directory(original_path) # cwd = self.fm.get_directory(original_path)
cwd.load_content() # cwd.load_content()
original_path = cwd.path # original_path = cwd.path
parts = self.line.split() # parts = self.line.split()
au_flags = parts[1:] # au_flags = parts[1:]
descr = "compressing files in: " + os.path.basename(parts[1]) # descr = "compressing files in: " + os.path.basename(parts[1])
obj = CommandLoader( # obj = CommandLoader(
args=["apack"] # args=["apack"]
+ au_flags # + au_flags
+ [os.path.relpath(f.path, cwd.path) for f in marked_files], # + [os.path.relpath(f.path, cwd.path) for f in marked_files],
descr=descr, # descr=descr,
read=True, # read=True,
) # )
obj.signal_bind("after", refresh) # obj.signal_bind("after", refresh)
self.fm.loader.add(obj) # self.fm.loader.add(obj)
def tab(self, tabnum): # def tab(self, tabnum):
"""Complete with current folder name""" # """Complete with current folder name"""
extension = [".zip", ".tar.gz", ".rar", ".7z"] # extension = [".zip", ".tar.gz", ".rar", ".7z"]
return [ # return [
"compress " + os.path.basename(self.fm.thisdir.path) + ext # "compress " + os.path.basename(self.fm.thisdir.path) + ext
for ext in extension # for ext in extension
] # ]
class mkcd(Command): class mkcd(Command):