Last active
February 26, 2025 16:59
-
-
Save chadbaldwin/537a26a59fab2c0630e7ee2f09ae76f3 to your computer and use it in GitHub Desktop.
Testing globs in ripgrep
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $string = 'Functions' | |
| $result = foreach ($l in '','*','/','*/','**/') { | |
| foreach ($r in '','*','/','/*','/**') { | |
| $glob = "!${l}${string}${r}" | |
| $stat = Measure-Command { $list = rg --files -g "${glob}" } | |
| [pscustomobject]@{ | |
| Glob = $glob | |
| Count = $list.Count | |
| ExecTimeMS = $stat.Milliseconds | |
| } | |
| } | |
| } | |
| $result | ft -AutoSize |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Returns something that looks like this:
Keep in mind, this code includes
*which means it will also do partial matches of a directory name. For example*Functionswill also match withUser Functions.Typically the way I use this script is to first figure out manually how many files should be included in my search by simply selecting and deselecting the directories in Windows Explorer, then viewing properties to get the file count. Then I line that up with the results of this script.
Typically I only need to do this once or twice before I remember how ripgrep handles globs again...It's just not something I use every day, so I tend to forget ๐
In this particular case, I want to exclude the
Functionsdirectory but I have some directories that contain the stringFunctionsthat I want to include. The file count I'm looking for is24914. So I'll then look for the simplest glob expression that has that file count, which in this case is simply!FunctionsThings get a little more complicated if you want to exclude certain sub-folders, or certain file types under certain sub-folders, etc....For example, "exclude all txt files contained in
logdirectories".