Migemo version of the: find command,: mfind

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

Migemo version of the: find command,: mfind
Align the version of chromedriver_binary
Open Chrome version of LINE from the command line [Linux]
Find out the version of the language you are running
Test the version of the argparse module
Find the definition of the value of errno
Raise the version of pyenv itself
pyenv-change the python version of virtualenv
Change the Python version of Homebrew
Find the area of the union of overlapping rectangles
How to check the version of Django
About the virtual environment of python version 3.7
[Python] Try pydash of the Python version of lodash
Notice the completion of a time-consuming command
Find the coefficients of the least squares polynomial
Try the python version of emacs-org parser orgparse
How to find the area of the Voronoi diagram
Combinatorial optimization to find the hand of "Millijan"
The story of making the Mel Icon Generator version2
Use the latest version of PyCharm on Ubuntu
A note about the python version of python virtualenv
Find the divisor of the value entered in python
Try the free version of Progate [Python I]
The story of misreading the swap line of the top command
Find the solution of the nth-order equation in python
Find out the day of the week with datetime
Find the geometric mean of n! Using Python
Sort files updated within the period specified by the find command in order of size
Find the cumulative distribution function by sorting (Python version)
Scraping the usage history of the community cycle PhantomJS version
Gradually display the output of the command executed by subprocess.Popen
Install the latest version of CMake on Ubuntu 18.04.4 LTS
Projecet Euler 12 Find the number of divisors without division.
The story of stopping the production service with the hostname command
Find the sum of unique values with pandas crosstab
Find out the location of Python class definition files.
Let's clear the ambiguity of the hyphen (-) of the su command now! !!
I followed the implementation of the du command (first half)
Find out the location of packages installed with pip
Let's use the Python version of the Confluence API module.
[Django] Change the Default IP address of the runserver command
Manage the package version number of requirements.txt with pip-tools
The latest version of Pillow 7.0.0 will kill the pytorch transform.
Check the type and version of your Linux distribution
Understand the attributes of Linux files (ls -l command)
The beginning of cif2cell
memorandum of vi command
Get the GNOME version
The meaning of self
Installation of OpenMDAO (version 1.7.1)
CentOS version confirmation command
the zen of Python
The story of sys.path.append ()
About the service command
Install the pip command
Find, locate command summary
Revenge of the Types: Revenge of types
How to pass the execution result of a shell command in a list in Python (non-blocking version)
Get the output value of the command (as received by xargs)
Notes on the version of CUDA, cuDNN where tensorflow-gpu worked
I tried to find the entropy of the image with python