Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Acces parent directory from fzf #125

Closed
olethanh opened this issue Feb 9, 2015 · 4 comments
Closed

Acces parent directory from fzf #125

olethanh opened this issue Feb 9, 2015 · 4 comments
Labels

Comments

@olethanh
Copy link

olethanh commented Feb 9, 2015

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

@junegunn
Copy link
Owner

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>

@rcywongaa
Copy link

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)

@amenl
Copy link

amenl commented Jul 16, 2020

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!

@Tinkidinki
Copy link

Tinkidinki commented Jan 26, 2021

My issue was that I wanted to access any file/folder present anywhere in the HOME directory irrespective of the present working directory. To do so, I changed the default command by adding the following in my .bashrc:

export FZF_DEFAULT_COMMAND="find ~"
export FZF_CTRL_T_COMMAND="find ~"
export FZF_ALT_C_COMMAND="find ~"

Hope this helps!

Also, thank you junegunn for this amazing tool!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants