2024-06-02 13:36:37 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# To start formatting a file, add a line that contains:
|
|
|
|
# @format-begin
|
|
|
|
# Formatting in that file can later be disabled adding another line with:
|
|
|
|
# @format-end
|
|
|
|
#
|
|
|
|
# It can be reenabled again later in the file.
|
|
|
|
#
|
|
|
|
# Finally, call: make format
|
|
|
|
|
|
|
|
REBAR=$1
|
|
|
|
|
2024-05-06 13:41:23 +02:00
|
|
|
FORMAT()
|
|
|
|
{
|
|
|
|
FPATH=$1
|
|
|
|
ERLS=$(git grep --name-only @format-begin "$FPATH"/)
|
2024-06-02 13:36:37 +02:00
|
|
|
|
|
|
|
for ERL in $ERLS; do
|
|
|
|
csplit --quiet --prefix=$ERL-format- $ERL /@format-/ "{*}"
|
|
|
|
done
|
|
|
|
|
2024-05-06 13:41:23 +02:00
|
|
|
EFMTS=$(find "$FPATH"/*-format-* -type f -exec grep --files-with-matches "@format-begin" '{}' ';')
|
2024-06-02 13:36:37 +02:00
|
|
|
EFMTS2=""
|
|
|
|
for EFMT in $EFMTS; do
|
|
|
|
EFMTS2="$EFMTS2 --files $EFMT"
|
|
|
|
done
|
|
|
|
$REBAR format $EFMTS2
|
|
|
|
|
|
|
|
for ERL in $ERLS; do
|
|
|
|
SPLITS=$(find $ERL-format-* -type f)
|
|
|
|
rm $ERL
|
|
|
|
for SPLIT in $SPLITS; do
|
|
|
|
cat $SPLIT >> $ERL
|
|
|
|
rm $SPLIT
|
|
|
|
done
|
|
|
|
done
|
2024-05-06 13:41:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
FORMAT src
|
|
|
|
FORMAT test
|