The basic part is: find as it is.
Naturally you need the cmigemo command and its dictionary (I think it will come in if you put in cmigemo)
At first, I tried to use PyMigemo, but I can't install it with Python3, and I don't know Python, so it seems to be difficult. I secretly launch the cmigemo command with popen and use it.
In rc.conf
rc.conf
map f console mfind
It will be convenient to do it. (Don't forget to put a space at the end of the line!)
commands.py
# Copyright (C) 2012 anekos
# Copyright (C) 2009, 2010, 2011 Roman Zimbelmann <[email protected]>
# This configuration file is licensed under the same terms as ranger.
#
# ranger - http://ranger.nongnu.org/
class mfind(Command):
"""
:mfind <EXPR{2,}>
Migemized find.
"""
tab = Command._tab_directory_content
last_rexpr = None
migemo = None
def get_instance (self):
if not self.migemo:
from subprocess import Popen, PIPE
self.migemo = Popen(["cmigemo", "-q", "-d", "/usr/share/migemo/utf-8/migemo-dict"], stdout=PIPE, stdin=PIPE)
return self.migemo
def get_rexpr (self, expr):
if not expr or len(expr) <= 1:
return None
m = self.get_instance()
m.stdin.write(bytearray(expr + "\n", "UTF-8"))
migemo_result = str(m.stdout.readline(), "UTF-8").rstrip()
try:
import re
return re.compile(migemo_result, re.L | re.U | re.I)
except:
return None
def execute (self):
if self.quick():
self.fm.move(right=1)
self.fm.block_input(0.5)
else:
self.fm.cd(self.rest(1))
# for n/N (search_next)
if self.last_rexpr:
self.fm.thistab.last_search = self.last_rexpr
self.fm.search_method = 'search'
def quick(self):
cwd = self.fm.thisdir
arg = self.rest(1)
if not arg:
return False
if arg == '.':
return False
if arg == '..':
return True
rexpr = self.get_rexpr(arg)
self.last_rexpr = rexpr
if not rexpr:
return False
count = 0
deq = deque(cwd.files)
deq.rotate(-cwd.pointer)
i = 0
for fsobj in deq:
from re import search
if search(rexpr, fsobj.basename):
count += 1
if count == 1:
cwd.move(to=(cwd.pointer + i) % len(cwd.files))
self.fm.thisfile = cwd.pointed_obj
if count > 1:
return False
i += 1
return count == 1
Recommended Posts