Photo by Ag PIC / Unsplash

Tiny Tool: checkRefs.sh

tiny tool Jul 16, 2025 (Jul 18, 2025) Loading...
while read -r referenced_String; do
    matches=$(grep -Flsi "$referenced_String" *)
    echo "## ${referenced_String}"
    if [ -n "$matches" ]; then
        echo "$matches"
    else
        echo "unreferenced"
    fi
done

Used with ls -1 ../templates | sh ../checkRefs.sh, this will check the files in the current directory to see which ones use a file from ../templates

I used this when building playbooks, to see which templates were used by files in the current directory – and which were unused. If a file referenced two templates, I could see that, too.

I built the tool because I did the work by hand a couple of times, and that became slow and error-prone as the number of files and strings increased. I couldn't find a way to make a tool (either on the commandline or within my IDE) do it. So it's tool time. Making it took about 15 minutes, and taught me some stuff – time well spent. Writing about making it has taken an hour.

I imagine I'll use it generally: I'll certainly use it on my current project again.

Subscribers get to see how I used LLMs Qwen3 and Claude3.7Sonnet.

Member reactions

Reactions are loading...

Sign in to leave reactions on posts

Tags

Comments

Sign in or become a Workroom Productions member to read and leave comments.

James Lyndsay

Getting better at software testing. Singing in Bulgarian. Staying in. Going out. Listening. Talking. Writing. Making.

Great! You've successfully subscribed.
Great! Next, complete checkout for full access.
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.