Code Monkey home page Code Monkey logo

Comments (6)

justinmk avatar justinmk commented on May 21, 2024

derp, may I ask what ${1:-*} is doing actually? I can't figure out how to get it to include hidden files the current directory. Is it a subshell? A glob? An awk expression? I'm having a hard time googling it. Thanks very much.

from fzf.

junegunn avatar junegunn commented on May 21, 2024

Hi, thanks for your interest in fzf.

If foo is a directory in the current directory, try fzf -x with the following inputs

Without stdin pipe, fzf command will use find command to populate the list of files and symlinks under the current directory, excluding hidden files and directories. (The actual command can be seen here: https://github.com/junegunn/fzf/blob/master/fzf#L496) The list will not contain the names of the subdirectories.

^foo returns all results starting with foo, including the foo directory

Therefore, this is not something we can expect, you shouldn't be able to match foo directory itself. Could you check again?

Try find ${1:-*} 2> /dev/null | fzf -x
^foo$ returns nothing

You're right, currently fzf will look for items that start with foo$, I'll fix this behavior.

derp, may I ask what ${1:-*} is doing actually?

$1 is the first argument to the function, and ${1:-*} evaluates to * if the argument is empty (or not given)

Take the following example:

do_fzf() {
  find ${1:-*} 2> /dev/null | fzf -x
}
  • do_fzf evaluates to
    • find * 2> /dev/null | fzf -x
  • do_fzf .
    • find . 2> /dev/null | fzf -x

The difference is that * will not match hidden files and directories that are direct children of the current directory. Usually I work in the root directory of a git repository, so * is a concise way to ignore .git directory. (The command in https://github.com/junegunn/fzf/blob/master/fzf#L496 is the correct way to ignore all the hidden files, but a bit lengthy)

Hmm, it seems there is a confusing example on the README page, I'll update the documentation as well.

from fzf.

junegunn avatar junegunn commented on May 21, 2024

^xxx$ has been fixed. Thanks for the report :)

I can't figure out how to get it to include hidden files the current directory.

  1. All the files and directories (and symlinks): find .
  2. Exclude .git directories: find . -name .git -prune -o -print
  3. Only directories (excluding .git): find . -name .git -prune -o -type d -print

So basically, you don't need ${1:-*} or ${1:-.} if you're only interested in the current directory.
I wrote ${1:-*} in the examples to allow something like fd ~/github in addition to simple fd

from fzf.

justinmk avatar justinmk commented on May 21, 2024

you shouldn't be able to match foo directory itself. Could you check again?

Maybe I wasn't clear: foo is in the current directory. It is not itself the current directory.

${1:-*} evaluates to *

Thanks, I should have realized that since it is inside a function definition 😴

All the files and directories (and symlinks): find .

Yeah, the readme example got me and I wasn't thinking carefully. Thanks! Here's what I'm using now:

if [ -f ~/.fzf.bash ]; then
  source ~/.fzf.bash
  f() { # fzf / includes hidden directories
    find . -name .git -prune -o $1 -print 2> /dev/null | sed 's@^..\(.*\)$@\1@' | fzf -x
  }
  fd() { # fzf / change to directory
    cd $(f "-type d")
  }
fi

f() fuzzy-searches everything except .git, and it trims the initial ./ prepended by find ., so the output is formatted nicer (which makes searching with fzf -x nicer).

from fzf.

junegunn avatar junegunn commented on May 21, 2024

Hey, thanks for the feedback!

Maybe I wasn't clear: foo is in the current directory. It is not itself the current directory.

No I don't think there was a misunderstanding. The default find command does not print directories:

find * -path '*/\\.*' -prune -o -type f -print -o -type l -print

As you can see, it only prints regular files and symlinks. Try

mkdir /tmp/fzf-test
cd /tmp/fzf-test
mkdir directory
touch file
ln -s directory symlink
fzf -x

and you'll see that directory is not in the list.
So I couldn't understand how you could match foo directory in the first place.

Regarding your bash functions, I think sed 's@^..\(.*\)$@\1@' can be written concisely as sed s/..// 😃

from fzf.

justinmk avatar justinmk commented on May 21, 2024

The default find command does not print directories:
find * -path '/.' -prune -o -type f -print -o -type l -print

I see, you mean the default fzf find call. I thought you mean plain old find. I guess my original report was wrong in that regard.

sed 's@^..(.*)$@\1@' can be written concisely as sed s/..//

Much better, thanks!

from fzf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.