-
Notifications
You must be signed in to change notification settings - Fork 1
/
refactor
22 lines (21 loc) · 1.17 KB
/
refactor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/bin/bash
git ls-files '*.st' -z | # List all files, then iterate through them and save their content
while IFS= read -rd '' f; do \
contents=$( \
sed -E 's/(\S)(@)/\1\ \2/g' < "$f" | # Add spaces before '@'
sed -E 's/(@)(\S)/\1\ \2/g' | # Add spaces after '@'
sed -E 's/([aA])(\s?M2)/\1n\2/g' | # Replace 'aM2', 'a M2', 'A M2', 'AM2' with 'anM2', 'an M2', 'An M2', 'AnM2'
sed -E 's/(\()(\s+)/\1/g' | # Remove spaces after opening brackets
sed -E 's/(\s+)(\))/\2/g' | # Remove spaces before closing brackets
sed -E 's/(\S)(\s+)$/\1/g' | # Remove trailing spaces
perl -p0e 's/^([^\[]+?)(\s\s+)(\|)/\1\n\t\3/s' | # Remove empty lines before args
perl -p0e 's/^([^\[]+?)(\|)(\s\s+)([^\s])/\1\2\n\t\4/s' | # Remove empty lines after args
perl -p0e 's/(\.)(\s*)$/\2/s' ); # Remove final point
echo "$contents" > "$f"; # Write back file. Fixes any wrong newlines.
done
git ls-files '*.md' -z |
while IFS= read -rd '' f; do \
contents=$( \
sed -E 's/([aA])(\s?M2)/\1n\2/g' < "$f" ); # Replace 'aM2', 'a M2', 'A M2', 'AM2' with 'anM2', 'an M2', 'An M2', 'AnM2'
echo "$contents" > "$f";
done