Skip to content

Instantly share code, notes, and snippets.

@leogdion
Created January 25, 2024 21:47
Show Gist options
  • Save leogdion/ba9bb09f7acc4a374b3bddd8e2ca20b4 to your computer and use it in GitHub Desktop.
Save leogdion/ba9bb09f7acc4a374b3bddd8e2ca20b4 to your computer and use it in GitHub Desktop.
#!/bin/bash
SOURCE_DIR="/path/to/your/source/directory"
find "$SOURCE_DIR" -name "*.swift" -type f -print0 | while IFS= read -r -d '' file; do
# Create a temporary file for editing
tmp_file=$(mktemp)
# Use awk to perform the replacement and save to the temporary file
awk '
BEGIN { in_block = 0; }
/\/\*\*/ { in_block = 1; print "/// A struct representing an Atom category."; next; }
/\*\// { in_block = 0; print "/// - SeeAlso: `EntryCategory`"; next; }
{ if (in_block) { gsub(/^ \*/, "/// "); print "///" $0; } else { print; } }
' "$file" > "$tmp_file"
# Overwrite the original file with the temporary file
mv "$tmp_file" "$file"
echo "Updated: $file"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment