1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

似たファイルをまとめてマークするコマンドを追加する

Posted at

before

こんな感じにファイルが並んでいるときに、

:mark_similars

すると、

after

同じような名前のファイルだけ、マークできる!

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-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
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?