gotbletu / shownotes

notes for videos from my youtube channel
https://www.youtube.com/user/gotbletu
GNU General Public License v3.0
911 stars 173 forks source link

How do I locate only from current directory in ranger with `ranger_file_locate_fzf`? #46

Closed kohane27 closed 2 years ago

kohane27 commented 2 years ago

Hello there! First of all, thank you for making these awesome tutorials and scripts. They are indeed very handy and useful.

Let's say I'm currently in dir ~./.config/ in ranger. I want to search within current directory, i.e., ~./.config/. Currently, if I trigger <C-g>, fzf is searched from home or media dir. I just want to search within current directory. How do I achieve that?

From shownotes/ranger_file_locate_fzf.md:

class fzf_locate(Command):
    """
    :fzf_locate

    Find a file using fzf.

    With a prefix argument select only directories.

    See: https://github.com/junegunn/fzf
    """
    def execute(self):
        import subprocess
        if self.quantifier:
            command="locate home media | fzf -e -i"
        else:
            command="locate home media | fzf -e -i"
        fzf = self.fm.execute_command(command, stdout=subprocess.PIPE)
        stdout, stderr = fzf.communicate()
        if fzf.returncode == 0:
            fzf_file = os.path.abspath(stdout.decode('utf-8').rstrip('\n'))
            if os.path.isdir(fzf_file):
                self.fm.cd(fzf_file)
            else:
                self.fm.select_file(fzf_file)

I think the line that should be changed is the following:

else:
    command="locate home media | fzf -e -i"

I've tried

command="echo $PWD | fzf -e -i"

or

command="shell echo $PWD | fzf -e -i"

or

command="shell echo -n %d | fzf -e -i"

but to no avail.

Any help is much appreciated. Thank you again!

gotbletu commented 2 years ago

use the fzf_select code, is on the same page map fzf_select

kohane27 commented 2 years ago

Thank you for such a quick reply. I just found the video of yours on this topic and realized the existence of fzf_select.

One thing is that the trigger <C-F> conflicted with the default copymap <PAGEDOWN> <C-F> in ranger. Once I disabled the default it works like a charm!

gotbletu commented 2 years ago

no probs, you can map to any hotkey you like in ranger