vault backup: 2025-02-12 10:22:32

This commit is contained in:
Dane Sabo 2025-02-12 10:22:32 -05:00
parent b8e589b05c
commit bafd220739
2 changed files with 48 additions and 30 deletions

View File

@ -0,0 +1,17 @@
Generated by ChatGPT on 2025-02-12
# Table of Contents for 300s School
## Subdirectories
- [[ME 2016 - Nonlinear Dynamical Systems 1/ME 2016 - Nonlinear Dynamical Systems 1 - README]]
- [[ME 2046 - Digital Control Theory/ME 2046 - Digital Control Theory - README]]
- [[ME 2085 - Graduate Seminar/ME 2085 - Graduate Seminar - README]]
- [[ME 2150 - High Assurance Cyber-Physical Systems/ME 2150 - High Assurance Cyber-Physical Systems - README]]
- [[ME 3100 - Engineering Research and Leadership Management/ME 3100 - Engineering Research and Leadership Management - README]]
- [[NUCE 2100 - Fundamentals of Nuclear Engineering/NUCE 2100 - Fundamentals of Nuclear Engineering - README]]
- [[NUCE 2103 - Integration of Plant Systems with the Reactor Core/NUCE 2103 - Integration of Plant Systems with the Reactor Core - README]]
- [[NUCE 2113 - Radiation Detection and Measurement/NUCE 2113 - Radiation Detection and Measurement - README]]
## Files
- [[reddup.sh]]

View File

@ -3,38 +3,42 @@
# Author: ChatGPT # Author: ChatGPT
# Generated on: $(date '+%Y-%m-%d') # Generated on: $(date '+%Y-%m-%d')
# #
# This script recursively creates or updates a table-of-contents README file in each # This script recursively creates or updates a table-of-contents README
# non-hidden directory. The file is named "Folder Name - README.md". # file in each non-hidden directory. The file is named "Folder Name - README.md".
# #
# Each README includes: # Each README includes:
# - An author/date header. # - A header with an author/date line.
# - A header with the folder's name. # - A header with the folder's name.
# - An alphabetically sorted list of immediate subdirectories, # - An alphabetically sorted list of immediate subdirectories, with links
# with links to that subdirectorys own README. # to that subdirectorys own README.
# - An alphabetically sorted list of immediate files (excluding # - An alphabetically sorted list of immediate files (excluding the generated README).
# the generated README).
# #
# Hidden directories (or any directory under a hidden parent such as .git) # Hidden directories (or any directory under a hidden parent such as .git) are skipped.
# are skipped.
# #
# This version optimizes updates by comparing the new content (ignoring the header) # The script only updates a README if the "body" (everything from line 3 on)
# to the existing file and only updating if there are changes. # has changed. It also prints a progress indicator like "[x/y] Updated: {dir}".
# ------------------------------------------------------------------ # ------------------------------------------------------------------
# If you want to remove existing README files, comment out or remove the next line.
# find . -type f -name '* - README.md' -delete
# Set the base directory (change "." if necessary) # Set the base directory (change "." if necessary)
base_dir="." base_dir="."
# Recursively process every directory starting from base_dir. # Build an array of directories to process.
find "$base_dir" -type d -print0 | while IFS= read -r -d '' dir; do dirs=()
# Skip directories that are hidden or are within a hidden directory (like .git) while IFS= read -r -d '' dir; do
if [[ "$(basename "$dir")" == .* ]] || [[ "$dir" == *"/.git"* ]]; then # Skip directories whose basename starts with a dot or whose path contains "/.git"
if [[ "$(basename "$dir")" == .* ]] || [[ "$dir" == *"/.git"* ]] || [[ "$dir" == *"/.obsidian"* ]] ; then
continue continue
fi fi
dirs+=( "$dir" )
done < <(find "$base_dir" -type d -print0)
# For the top-level directory, use its actual name (using $PWD) instead of "." total=${#dirs[@]}
count=0
# Process each directory in the array.
for dir in "${dirs[@]}"; do
count=$((count+1))
# For the top-level directory, use the actual name (using $PWD); otherwise, use the directory's basename.
if [ "$dir" = "$base_dir" ]; then if [ "$dir" = "$base_dir" ]; then
base=$(basename "$PWD") base=$(basename "$PWD")
else else
@ -48,7 +52,6 @@ find "$base_dir" -type d -print0 | while IFS= read -r -d '' dir; do
tmpfile=$(mktemp) tmpfile=$(mktemp)
# Write the header into the temporary file. # Write the header into the temporary file.
# (We include the date here but will ignore it when comparing changes.)
{ {
echo "Generated by ChatGPT on $(date '+%Y-%m-%d')" echo "Generated by ChatGPT on $(date '+%Y-%m-%d')"
echo "" echo ""
@ -60,7 +63,6 @@ find "$base_dir" -type d -print0 | while IFS= read -r -d '' dir; do
# Process Subdirectories # Process Subdirectories
######################### #########################
subdirs=() subdirs=()
# Find immediate subdirectories (depth 1) in the current directory, skipping hidden ones.
while IFS= read -r -d '' subdir; do while IFS= read -r -d '' subdir; do
sub_basename=$(basename "$subdir") sub_basename=$(basename "$subdir")
if [ -n "$sub_basename" ]; then if [ -n "$sub_basename" ]; then
@ -73,8 +75,7 @@ find "$base_dir" -type d -print0 | while IFS= read -r -d '' dir; do
mapfile -t sorted_subdirs < <(printf "%s\n" "${subdirs[@]}" | sort) mapfile -t sorted_subdirs < <(printf "%s\n" "${subdirs[@]}" | sort)
echo "## Subdirectories" >> "$tmpfile" echo "## Subdirectories" >> "$tmpfile"
for sub in "${sorted_subdirs[@]}"; do for sub in "${sorted_subdirs[@]}"; do
# Build the link to the subdirectory's README file. # Link format: [[Subfolder/Subfolder - README]]
# Format: [[Subfolder/Subfolder - README]]
line="- [[${sub}/${sub} - README]]" line="- [[${sub}/${sub} - README]]"
printf "%s\n" "$line" >> "$tmpfile" printf "%s\n" "$line" >> "$tmpfile"
done done
@ -85,7 +86,6 @@ find "$base_dir" -type d -print0 | while IFS= read -r -d '' dir; do
# Process Files # Process Files
################# #################
files=() files=()
# Find immediate files (depth 1), excluding the generated README file.
while IFS= read -r -d '' file; do while IFS= read -r -d '' file; do
fbase=$(basename "$file") fbase=$(basename "$file")
if [ -n "$fbase" ]; then if [ -n "$fbase" ]; then
@ -104,17 +104,18 @@ find "$base_dir" -type d -print0 | while IFS= read -r -d '' dir; do
echo "" >> "$tmpfile" echo "" >> "$tmpfile"
fi fi
# If the README file exists, compare its body (ignoring the header) with the new content. # If the README already exists, compare its body (from line 3 onward)
# Here, we assume the header is the first two lines (the attribution and a blank line). # with the new content (ignoring the first two lines, which contain the date header).
if [ -f "$readme" ]; then if [ -f "$readme" ]; then
if diff -q <(tail -n +3 "$tmpfile") <(tail -n +3 "$readme") >/dev/null; then if diff -q <(tail -n +3 "$tmpfile") <(tail -n +3 "$readme") >/dev/null; then
# No change in the body; do not update.
rm "$tmpfile" rm "$tmpfile"
echo "[$count/$total] No change: $dir"
continue continue
fi fi
fi fi
# If new or changed, move the temporary file to the target README. # Update (or create) the README.
mv "$tmpfile" "$readme" mv "$tmpfile" "$readme"
echo "[$count/$total] Updated: $dir"
done done