示例#1
0
    def list_remotes_in_vim_buffer(self):
        if not Shell.isinPATH('rclone'):
            self.install_rclone()

        remotes = set(self.cmd_listremotes())
        local_remotes = set(super(Rclone, self).ls(self.root_dir))
        for remote in remotes.difference(local_remotes):
            Shell.mkdir(os.path.join(self.root_dir, remote))
        for remote in local_remotes.difference(remotes):
            Shell.rm(os.path.join(self.root_dir, remote))

        if len(remotes) > 0:
            Vim.command(f'NETRTabdrop {self.root_dir}')
        else:
            Vim.ErrorMsg(
                "There's no remote now. Run 'rclone config' in a terminal to "
                "setup remotes and restart vim again.")
示例#2
0
 def view_image(self):
     try:
         import ueberzug
     except ModuleNotFoundError:
         Vim.ErrorMsg('Please install ueberzug for image preview')
         self.view_mime()
         return
     path = self.path
     if self.path.endswith('gif') and Shell.isinPATH('convert'):
         if self.path not in self.tempfile_cache:
             dir = tempfile.TemporaryDirectory().name
             Shell.mkdir(dir)
             self.tempfile_cache[self.path] = dir
         dir = self.tempfile_cache[self.path]
         path = dir
         Shell.run(f'convert -deconstruct  "{self.path}" {dir}/a.png')
     Vim.AsyncRun(f'{util.GenNetRangerScriptCmd("image_preview")}\
                     "{path}" {self.total_width} {self.preview_width}',
                  term=True,
                  termopencmd='')
     Vim.command('setlocal nocursorline')
示例#3
0
    def __init__(self, path):
        self.rules = []

        if not os.path.isfile(path):
            Shell.cp(os.path.join(config_dir, 'rifle.conf'), path)

        with open(path, 'r') as f:
            for i, line in enumerate(f):
                try:
                    # remove things after the first # (including)
                    line = line[:line.index('#')]
                except ValueError:
                    pass

                line = line.strip()
                if len(line) == 0:
                    continue
                sp = line.split('=')
                if len(sp) != 2:
                    Vim.ErrorMsg(
                        'invalid rule: rifle.conf line {}. There should be one'
                        ' and only one "=" for each line'.format(i + 1))
                    continue

                tests = []
                for test in sp[0].strip().split(','):
                    testSp = [e for e in test.split(' ') if e != '']
                    tests.append(globals()[testSp[0]](*testSp[1:]))
                command = sp[1].strip()

                # simple case, used specify only the command
                # For sophisicated command like bash -c "command {}"
                # user should add '{}' themselves
                if '{}' not in command:
                    command = command + ' {}'
                self.rules.append((tests, command))
示例#4
0
 def print_error(job_id, err_msg):
     # Truncate unnecessary message if from fs_server.py
     ind = err_msg.rfind('FSServerException: ')
     if ind > 0:
         err_msg = err_msg[ind + 19:]
     Vim.ErrorMsg(err_msg)
示例#5
0
 def run(cls, cmd):
     try:
         return subprocess.check_output(
             cmd, shell=True, stderr=subprocess.STDOUT).decode('utf-8')
     except subprocess.CalledProcessError as e:
         Vim.ErrorMsg(e)
示例#6
0
 def on_stderr(job_id, err_msg):
     ind = err_msg.rfind('FSServerException: ')
     if ind > 0:
         err_msg = err_msg[ind + 19:]
     Vim.ErrorMsg(err_msg)