2

How do I get ag to list all files, including empty ones?

+ravi@boxy:~$ mkdir new && cd new
+ravi@boxy:~/new$ echo stuff > non-empty && touch empty
+ravi@boxy:~/new$ ag -ul
non-empty
+ravi@boxy:~/new$

How do I get empty to appear in the example above?

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
Tom Hale
  • 28,728
  • 32
  • 139
  • 229
  • Just a guess but perhaps it's an optimization that says empty files can't match any text? – Jeff Schaller Aug 14 '16 at 13:20
  • Why do you want to find empty files with `ag`? The entire point of `ag` is to avoid searching files that have no chance to contain useful patterns. – Satō Katsura Aug 14 '16 at 16:00
  • They are files. Why break -l if a null pattern is supposed to match all files? ...Because it's faster and (and generally better) than 'find'. – Tom Hale Aug 14 '16 at 17:07

2 Answers2

3

My suspicion is confirmed by looking at the source in the search_file function around line 258, where it checks the file's size. If the size is zero, it bails out:

if (f_len == 0) {
    log_debug("Skipping %s: file is empty.", file_full_path);
    goto cleanup;
}

To confirm that this is the case, you may be able to use the --debug option.

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
  • Yes, it comes up in the debug output. I've raised an issue at: [ag not printing empty files with -ul](https://github.com/ggreer/the_silver_searcher/issues/956) – Tom Hale Aug 15 '16 at 01:14
0

As @Jeff answers, the code didn't previously support this. I made a Pull Request to fix the issue which has just now been merged in.

Note: The project maintainer is asking for help as his available time for ag is limited.

Tom Hale
  • 28,728
  • 32
  • 139
  • 229