Skip to content

Instantly share code, notes, and snippets.

@anekos
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anekos/29ef02cf15629ae57026 to your computer and use it in GitHub Desktop.
Save anekos/29ef02cf15629ae57026 to your computer and use it in GitHub Desktop.
ranger command - :mark_similars - Mark the files whose name is similar to the selected file.

Before

Before

After :mark_simalars

After

Requirements

Python Levenshtein module.

$ easy_install --user levenshtein
class mark_similars(Command):
"""
:mark_similars [<NAME>]
Mark the files whose name is similar to the selected file.
"""
do_mark = True
def execute(self):
from Levenshtein import ratio
arg = self.rest(1)
if not arg:
arg = self.fm.thisfile.basename
cwd = self.fm.thisdir
for file in cwd.files:
if ratio(arg, file.basename) > 0.65:
cwd.toggle_mark(file)
self.fm.ui.status.need_redraw = True
self.fm.ui.need_redraw = True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment