2021-02-06 Unignoring some files by ripgrep

I use the famous ripgrep tool a lot. It is extremely useful, especially being fast and having a nice Emacs interface (counsel-rg in my case). By the way, one thing I changed in the default setup was changing the -i option to -S. The former means search case-insensitively, the latter is an abbreviation of --smart-case, meaning search case-insensitively if the pattern is lower-case only and case-sensitively if it contains at least one upper-case letter. (This is similar to Emacs’ own incremental-search.) I have this line included in my init.el to accomplish this change:

(eval-after-load
    'counsel
  '(setq counsel-rg-base-command
	 (replace-regexp-in-string "-i" "-S" counsel-rg-base-command t t)))

It’s perhaps not the most beautiful way to do this, but it works.

This is not the main topic of this post, however. Recently, I encountered the following problem. I had some .gitignore​d files in a repository, but I wanted to include them in rg searches. (One use-case, though different than my one, would be to include some log files which are not committed in the repository in the searches.) This behavior can be enabled by the --no-ignore-vcs option, but it is not very comfortable to use and very crude (it just stops taking .gitignore into account altogether, and frankly, including node_modules in the search is no fun – it makes even rg choke). Here is a much better way: put a .ignore file in your repo and include a line like !*.log (i.e., inverted glob catching all log files), and you’re done! Very useful indeed.

CategoryEnglish, CategoryBlog