0

I want to use ripgrep on my Ubuntu 20 machine. I have installed it from various repos (apt, snap, cargo) and even built it myself but have always run into the same problem:

According to the manual one should be able to just run

rg 'pattern'

and ripgrep will just recursively search in the current working dir. However for me it always seems to expect a path specifier as well, shown by the fact that it will not find a match even if a file with the pattern is present in the top level of the current directory.

Ripgrep will only work if I do something like:

rg 'pattern' *

This would be not too much of a problem, but I intend to use ripgrep in a vim-addon which expects the behavior from the manual. So the question is: why does ripgrep behave so strangely and how do I fix the behavior?

Edit:

Running the command with the --debug flag gives the following output:

DEBUG|grep_regex::literal|grep-regex/src/literal.rs:59: literal prefixes detected: Literals { lits: [Complete(test)], limit_size: 250, limit_class: 10 }
DEBUG|globset|globset/src/lib.rs:435: built glob set; 0 literals, 0 basenames, 11 extensions, 0 prefixes, 0 suffixes, 0 required extensions, 0 regexes
DEBUG|globset|globset/src/lib.rs:435: built glob set; 0 literals, 0 basenames, 11 extensions, 0 prefixes, 0 suffixes, 0 required extensions, 0 regexes
DEBUG|globset|globset/src/lib.rs:435: built glob set; 0 literals, 0 basenames, 11 extensions, 0 prefixes, 0 suffixes, 0 required extensions, 0 regexes
DEBUG|globset|globset/src/lib.rs:435: built glob set; 0 literals, 0 basenames, 11 extensions, 0 prefixes, 0 suffixes, 0 required extensions, 0 regexes
DEBUG|globset|globset/src/lib.rs:430: glob converted to regex: Glob { glob: "**/*", re: "(?-u)^(?:/?|.*/)[^/]*$", opts: GlobOptions { case_insensitive: false, literal_separator: true, backslash_escape: true }, tokens: Tokens([RecursivePrefix, ZeroOrMore]) }
DEBUG|globset|globset/src/lib.rs:435: built glob set; 0 literals, 0 basenames, 0 extensions, 0 prefixes, 0 suffixes, 0 required extensions, 1 regexes
DEBUG|globset|globset/src/lib.rs:435: built glob set; 0 literals, 0 basenames, 11 extensions, 0 prefixes, 0 suffixes, 0 required extensions, 0 regexes
DEBUG|ignore::walk|ignore/src/walk.rs:1639: ignoring ./.cache: Ignore(IgnoreMatch(Gitignore(Glob { from: Some("./.gitignore"), original: "*", actual: "**/*", is_whitelist: false, is_only_dir: false })))

...

and then it is the same as the last line for each subfolder of my home directory.

7
  • ripgrep installed using apt from standard Ubuntu repos works as expected for me. Can you do a which rg to make sure you're calling the executable you expect? Sep 10, 2020 at 11:25
  • Well which rg shows /usr/bin/rg which I guess is what I expect.As stated above I have also compiled ripgrep from source and still face the same problem of having to specify a glob after my search.
    – Iconstrife
    Sep 10, 2020 at 11:29
  • As a sanity check, run echo "test" > test && rg "test". Note that this will overwrite any file called "test" in your current working directory so change the name if that causes you problems. Sep 10, 2020 at 11:35
  • I have more or less done that exact same check on each of the iterations (and have just now tried your exact command). Unfortunately it still does not find anything. Echoing the return code of the program also reveals that it exited with error code 1.
    – Iconstrife
    Sep 10, 2020 at 11:58
  • I don't have any great ideas on this one, does adding --debug yield any hints? Sep 10, 2020 at 12:05

1 Answer 1

3

Ok, so thanks to @Brian I have resolved the issue.

ripgrep has a built-in ignore logic, automatically ignoring the files it finds in .gitignore.

To save my dotfiles via git, I had setup a repository in my home directory, which by default ignores all files except the ones that I add using git add -f .... I.e. in my .gitignore file in the home directory I ignore all (*) files, which then in turn caused ripgrep to ignore them as well. I don't think that all too many will experience the same problem, but maybe this will help someone someday.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.