Skip to content

Commit

Permalink
Suggest ripgrep instead of the silver searcher
Browse files Browse the repository at this point in the history
Since BurntSushi/ripgrep#200 is fixed in
0.7.1, we can safely suggest ripgrep as the candidate generator as it
has a more precise implementation of gitignore filtering than the silver
searcher.
  • Loading branch information
junegunn committed Oct 23, 2017
1 parent eaf6eb8 commit 5784101
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ or `py`.

- `FZF_DEFAULT_COMMAND`
- Default command to use when input is tty
- e.g. `export FZF_DEFAULT_COMMAND='ag -g ""'`
- e.g. `export FZF_DEFAULT_COMMAND='rg --files'`
- `FZF_DEFAULT_OPTS`
- Default options
- e.g. `export FZF_DEFAULT_OPTS="--reverse --inline-info"`
Expand Down Expand Up @@ -369,17 +369,18 @@ export FZF_COMPLETION_TRIGGER='~~'
# Options to fzf command
export FZF_COMPLETION_OPTS='+c -x'

# Use ag instead of the default find command for listing path candidates.
# Use rg (https://github.com/BurntSushi/ripgrep) instead of the default find
# command for listing path candidates.
# - The first argument to the function is the base path to start traversal
# - See the source code (completion.{bash,zsh}) for the details.
# - ag only lists files, so we use with-dir script to augment the output
# - rg only lists files, so we use with-dir script to augment the output
_fzf_compgen_path() {
ag -g "" "$1" | with-dir "$1"
rg --files "$1" | with-dir "$1"
}

# Use ag to generate the list for directory completion
# Use rg to generate the list for directory completion
_fzf_compgen_dir() {
ag -g "" "$1" | only-dir "$1"
rg --files "$1" | only-dir "$1"
}
```

Expand Down Expand Up @@ -491,18 +492,17 @@ Tips

#### Respecting `.gitignore`, `.hgignore`, and `svn:ignore`

[ag](https://github.com/ggreer/the_silver_searcher) or
[rg](https://github.com/BurntSushi/ripgrep) will do the
filtering:
[ripgrep](https://github.com/BurntSushi/ripgrep) or [the silver
searcher](https://github.com/ggreer/the_silver_searcher) can do the filtering:

```sh
# Feed the output of ag into fzf
ag -g "" | fzf
# Feed the output of rg into fzf
rg --files | fzf

# Setting ag as the default source for fzf
export FZF_DEFAULT_COMMAND='ag -g ""'
# Setting rg as the default source for fzf
export FZF_DEFAULT_COMMAND='rg --files'

# Now fzf (w/o pipe) will use ag instead of find
# Now fzf (w/o pipe) will use rg instead of find
fzf

# To apply the command to CTRL-T as well
Expand All @@ -512,7 +512,7 @@ export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
If you don't want to exclude hidden files, use the following command:

```sh
export FZF_DEFAULT_COMMAND='ag --hidden --ignore .git -g ""'
export FZF_DEFAULT_COMMAND='rg --files --hidden --glob \!.git'
```

#### `git ls-tree` for fast traversal
Expand Down

8 comments on commit 5784101

@crapp
Copy link

@crapp crapp commented on 5784101 Oct 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rg doesn't support an additional ignore file like ag. For me this makes it unusable. Why can't you just mention both?

@junegunn
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why should I mention both? These are just examples, you don't have to follow.

@christianscott
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@crapp You can use a negative glob (not sure if this is the correct terminology) to ignore extra files, e.g. export FZF_DEFAULT_COMMAND='rg --files -g \'!*.jpg\''

@crapp
Copy link

@crapp crapp commented on 5784101 Oct 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry but I need to ignore entire directories. For example documentation generated by doxygen.

@christianscott
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about this? rg --files -g '!dir/**/*' Though I agree that it would be nice if rg had support for extra ignore files

@crapp
Copy link

@crapp crapp commented on 5784101 Oct 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@junegunn Absolutely but ag is available in many linux distributions by default whereas ripgrep isn't. Wouldn't hurt to mention ag as well. I am not allowed to install any software on our debian production server which isn't available in official repositories. you know people will try to use what you suggest even if this is just an example

@crapp
Copy link

@crapp crapp commented on 5784101 Oct 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chrfrasco we are sharing our agignore files within the project. there are 9 ignored directories and many more ignored files. putting this in a one line ripgrep call isn't very nice.

@SimenB
Copy link

@SimenB SimenB commented on 5784101 Dec 3, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rg supports addition ignore file

       --ignore-file FILE ...
              Specify additional ignore files for filtering file paths.  Ignore files should be in the git-
              ignore format and are matched relative to the current working directory.  These ignore  files
              have  lower  precedence  than all other ignore files.  When specifying multiple ignore files,
              earlier files have lower precedence than later files.

Please sign in to comment.