Files
3d-printer-models/generate-readme.sh
T
2025-09-04 11:54:55 -07:00

50 lines
1.3 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
HEADER_FILE="readme-header.md"
README_FILE="README.md"
# Create or truncate the README file
> "$README_FILE"
# Add the header to the README file
cat "$HEADER_FILE" >> "$README_FILE"
# Get a list of Git‑tracked directories (unique, sorted)
git_dirs=$(git ls-files | cut -d'/' -f1 | sort -u)
# Loop through each tracked directory
for dir in $git_dirs; do
# Ensure it's a directory
[ -d "$dir" ] || continue
# Add the section header
echo -e "\n## ${dir}\n" >> "$README_FILE"
# Embed PNG images
png_files=$(find "$dir" -maxdepth 1 -type f -name '*.png')
if [ -n "$png_files" ]; then
for png in $png_files; do
echo "![${png##*/}](${png})" >> "$README_FILE"
done
fi
# Add links to Markdown files
md_files=$(find "$dir" -maxdepth 1 -type f -name '*.md')
if [ -n "$md_files" ]; then
echo -e "\nDocumentation:\n" >> "$README_FILE"
for md in $md_files; do
echo "* [${md##*/}](${md})" >> "$README_FILE"
done
fi
# List .scad files
echo -e "\nModel files:\n" >> "$README_FILE"
scad_files=$(find "$dir" -type f -name '*.scad')
if [ -n "$scad_files" ]; then
for scad in $scad_files; do
# Strip leading directory component
echo "* ${scad#$dir/}" >> "$README_FILE"
done
fi
done