magbo system

fzf integration in ranger

Ranger is advanced file manager (like mc, Nautilus, Total Commander, …) but it uses key bindings and shortcuts like vim. It is in Debian’s repositories.

fzf (command-line fuzzy finder) is tool for searching files and directories. You can download it from github.com/junegunn/fzf

For integration create (or open) file ~/.config/ranger/commands.py and add function fzf_select. All file should looks like this:

from ranger.api.commands import Command


class fzf_select(Command):
    """
    :fzf_select

    Find a file using fzf.

    With a prefix argument select only directories.

    See: https://github.com/junegunn/fzf
    """
    def execute(self):
        import subprocess
        import os.path
        fzf = self.fm.execute_command("fzf +m", universal_newlines=True, stdout=subprocess.PIPE)
        stdout, stderr = fzf.communicate()
        if fzf.returncode == 0:
            fzf_file = os.path.abspath(stdout.rstrip('\n'))
            if os.path.isdir(fzf_file):
                self.fm.cd(fzf_file)
            else:
                self.fm.select_file(fzf_file)

Then restart ranger and type :fzf_select and start using fzf in ranger.

3 thoughts on “fzf integration in ranger

  1. Pingback: Change prompt in Ranger | posvic.eu

  2. Unfortunately in my home directory and all directories above that, the fzf command does not stop running, even though a correct fzf_file could be retrieved. Do you have any ideas why this happens?

Leave a Reply

Your email address will not be published. Required fields are marked *