Add a command to mark similar files together

before

When the files are lined up like this

:mark_similars

Then

after

Only files with similar names can be marked!

It is convenient to map it appropriately in rc.conf.

commands.py


from ranger.api.commands import *


class mark_similars(Command):
  """
  :mark_similars [<NAME>]

  Mark all similar files by the name.
  """
  do_mark = True

  def execute(self):
    from re import compile, sub, I, UNICODE

    arg = self.rest(1)
    if not arg:
      arg = self.fm.thisfile.basename

    pattern = compile('^' + sub(r'[^A-Gaa-Nichi-龠 a-zA-Z]+', '.+', arg) + '$', I | UNICODE)

    cwd = self.fm.thisdir
    for file in cwd.files:
      if pattern.search(file.basename):
        #cwd.mark_item(file, val=self.do_mark)
        cwd.toggle_mark(file)

    self.fm.ui.status.need_redraw = True
    self.fm.ui.need_redraw = True

Recommended Posts

Add a command to mark similar files together
Add a dictionary to MeCab
[Command] Command to get a list of files containing double-byte characters
To add a C module to MicroPython ...
[C language] [Linux] Try to create a simple Linux command * Just add! !!
Add a GPIO board to your computer. (1)
How to add a package with PyCharm
Create a command to delete all temporary files generated in a specific folder
Don't use rm command to delete files
Add a Python virtual environment to VSCode
[Python] Add comments to standard input files
Create a command to encode / decode Splunk base64
How to add a Python module search path
Use click to create a sub-sub command --netsted sub-sub command -
To add a module to python put in Julialang
Try to create a new command on linux
How to create a shortcut command for LINUX
Create a command to get the work log
[Wagtail] Add a login page to the Wagtail project
How to use the grep command to recursively search directories and files to a specified depth
How to write a GUI using the maya command
Try to make a command standby tool with python
How to add page numbers to PDF files (in Python)
I made a command to markdown the table clipboard
[Morphological analysis] How to add a new dictionary to Mecab
How to execute a command using subprocess in Python
How to reference static files in a Django project
2 ways to read all csv files in a folder
Let's add it to the environment variable from the command ~
Generate a bash script to add Datadog monitor settings
Unzip a lot of ZIP-compressed files with Linux commands to UTF8 and stick them together