Sample Header Ad - 728x90

How can I search only git tracked files with a specific file extension?

2 votes
2 answers
2777 views
I'd like to search all git tracked files that 1. has an .hs file extension and 2. contain the word import in any lines. I've tried to use git ls-files -z | xargs -0 rg -g '*.hs' "import" however unfortunately if you pass an explicit list of files to rg it seems to ignore the -g glob flag. I could potentially use grep to use some regex lookbehind to extract files with a specific file extension, or potentially filter the output from git ls-files -z (ensuring we keep the null separated filenames aspect, both approaches seem a bit clunky though... If anyone has any ideas.
Asked by Chris Stryczynski (6603 rep)
Jul 21, 2022, 06:12 PM
Last activity: Jul 21, 2022, 06:23 PM