2020-04-27 06:47:36 +00:00
|
|
|
import os
|
|
|
|
from ranger.core.loader import CommandLoader
|
|
|
|
from ranger.api.commands import Command
|
2020-10-20 08:49:49 +00:00
|
|
|
from ranger.gui.widgets import Widget
|
2020-10-21 05:41:20 +00:00
|
|
|
from ranger.gui.widgets.browsercolumn import BrowserColumn
|
|
|
|
|
2020-10-20 08:49:49 +00:00
|
|
|
|
|
|
|
Widget.vcsstatus_symb = {
|
|
|
|
'conflict': (
|
|
|
|
'X ', ['vcsconflict']),
|
|
|
|
'untracked': (
|
|
|
|
'? ', ['vcsuntracked']),
|
|
|
|
'deleted': (
|
|
|
|
'- ', ['vcschanged']),
|
|
|
|
'changed': (
|
|
|
|
'+ ', ['vcschanged']),
|
|
|
|
'staged': (
|
|
|
|
'* ', ['vcsstaged']),
|
|
|
|
'ignored': (
|
|
|
|
'· ', ['vcsignored']),
|
|
|
|
'sync': (
|
|
|
|
'✓ ', ['vcssync']),
|
|
|
|
'none': (
|
|
|
|
' ', []),
|
|
|
|
'unknown': (
|
|
|
|
'! ', ['vcsunknown']),
|
|
|
|
}
|
|
|
|
|
2020-10-21 05:41:20 +00:00
|
|
|
|
2020-10-20 08:49:49 +00:00
|
|
|
Widget.vcsremotestatus_symb = {
|
|
|
|
'diverged': (
|
|
|
|
' Y', ['vcsdiverged']),
|
|
|
|
'ahead': (
|
|
|
|
' >', ['vcsahead']),
|
|
|
|
'behind': (
|
|
|
|
' <', ['vcsbehind']),
|
|
|
|
'sync': (
|
|
|
|
' =', ['vcssync']),
|
|
|
|
'none': (
|
|
|
|
' ⌂ ', ['vcsnone']),
|
|
|
|
'unknown': (
|
|
|
|
' !', ['vcsunknown']),
|
|
|
|
}
|
2020-04-27 06:47:36 +00:00
|
|
|
|
2020-10-21 05:41:20 +00:00
|
|
|
|
|
|
|
def wrap_draw_vcsstring_display(origin):
|
|
|
|
def _draw_vcsstring_display(*args, **kwargs):
|
|
|
|
vcsstring = origin(*args, **kwargs)
|
|
|
|
if vcsstring and vcsstring[0] and vcsstring[0][0] == ' ':
|
|
|
|
vcsstring[0][0] = ' '
|
|
|
|
return vcsstring
|
|
|
|
return _draw_vcsstring_display
|
|
|
|
|
|
|
|
|
|
|
|
BrowserColumn._draw_vcsstring_display = wrap_draw_vcsstring_display(BrowserColumn._draw_vcsstring_display)
|
|
|
|
|
|
|
|
|
2020-04-27 06:47:36 +00:00
|
|
|
class extracthere(Command):
|
|
|
|
def execute(self):
|
|
|
|
""" Extract copied files to current directory """
|
|
|
|
copied_files = tuple(self.fm.copy_buffer)
|
|
|
|
|
|
|
|
if not copied_files:
|
|
|
|
return
|
|
|
|
|
|
|
|
def refresh(_):
|
|
|
|
cwd = self.fm.get_directory(original_path)
|
|
|
|
cwd.load_content()
|
|
|
|
|
|
|
|
one_file = copied_files[0]
|
|
|
|
cwd = self.fm.thisdir
|
|
|
|
original_path = cwd.path
|
|
|
|
au_flags = ['-X', cwd.path]
|
|
|
|
au_flags += self.line.split()[1:]
|
|
|
|
au_flags += ['-e']
|
|
|
|
|
|
|
|
self.fm.copy_buffer.clear()
|
|
|
|
self.fm.cut_buffer = False
|
|
|
|
if len(copied_files) == 1:
|
|
|
|
descr = "extracting: " + os.path.basename(one_file.path)
|
|
|
|
else:
|
|
|
|
descr = "extracting files from: " + os.path.basename(one_file.dirname)
|
|
|
|
obj = CommandLoader(args=['aunpack'] + au_flags \
|
|
|
|
+ [f.path for f in copied_files], descr=descr)
|
|
|
|
|
|
|
|
obj.signal_bind('after', refresh)
|
|
|
|
self.fm.loader.add(obj)
|
|
|
|
|
|
|
|
|
|
|
|
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]
|