Last active
November 3, 2023 22:34
-
-
Save wrhall/524cced4f4b5e64bca00e0b6df01fb50 to your computer and use it in GitHub Desktop.
This file contains 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
search_exported_names() { | |
local export_name="$1" | |
local file_list | |
local count | |
count=$(rg -F --type-add 'ts:*.ts' --type-add 'tsx:*.tsx' --type 'ts' --type 'tsx' -c --no-filename "${export_name}" < /dev/null | awk '{sum += $1} END {print sum}' || echo "0") | |
echo "Search term: ${export_name} - Count: ${count}" | |
} | |
rg --type-add 'ts:*.ts' --type-add 'tsx:*.tsx' --type 'ts' --type 'tsx' 'export (const|function|class|type|interface) \w+' -o --no-filename | awk '{print $3}' | sort | uniq > exported_names.txt | |
while IFS= read -r export_name; do | |
search_exported_names "$export_name" | |
done < exported_names.txt | grep -E ' - Count: 1$' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You could replace the count with 2 invocations of rg -- one that finds up to 2 files, and then the other which counts occurrences in the files. But this isn't obviously faster on my data: