Fzf: Acces parent directory from fzf

Created on 10 Feb 2015  路  3Comments  路  Source: junegunn/fzf

Hello,
first thanks for this wonderful and useful utility.

Would it be possible to add a way to go up the parent directory ? It would be especially useful when selecting a file via the Ctrl-T shortcut.

Thanks

question

Most helpful comment

Just leaving this here, you can do that with the following

$(cd .. && fzf)

In case you need the full path name, you can do

$(cd .. && find "$PWD" | fzf)

All 3 comments

fzf is just a unix filter (like grep) that does not know the meaning of the items that it processes, so it's not possible to change the source dynamically. If you're on bash you can try using fuzzy completion although it won't be as easy as just hitting CTRL-T.

vim ../**<TAB>

Just leaving this here, you can do that with the following

$(cd .. && fzf)

In case you need the full path name, you can do

$(cd .. && find "$PWD" | fzf)

Also, just leaving a note... I got it working this way (minimal example):

A function:

function F() { cd "$(fzf_cd "$PWD" )" }

A script (here named fzf_cd):

#!/bin/bash

FD=$( fd --type directory --color=always "." "$1" )

CD=$( echo "$FD" | fzf -m --bind "shift-left:abort+execute(fzf_cd '$1/..' )" )

echo "$CD"

The two parts (FD, CD) need to be separated so that there is at least '\n' piped to fzf (it won't work if fd produces no results in a leaf-directory).

You can make it work in ranger, by having this in your commands.py:

class fzf_cd(Command):

    def execute(self):

        exec = self.fm.execute_command("fzf_cd .", universal_newlines=True, stdout=PIPE)
        stdout, stderr = exec.communicate()

        if exec.returncode == 0:
            dest = stdout.rstrip('\n')

            if os.path.isdir(dest):
                self.fm.cd(dest)

            elif os.path.isfile(dest):
                self.fm.select_file(dest)

I would love to see a deeper integration of ranger and fzf, they're just meant to be together!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

firedev picture firedev  路  3Comments

ahmedelgabri picture ahmedelgabri  路  3Comments

kit494way picture kit494way  路  3Comments

fenuks picture fenuks  路  3Comments

erusev picture erusev  路  3Comments