1
0
Fork 0
mirror of https://github.com/processone/ejabberd synced 2025-10-03 09:49:18 +02:00
ejabberd/tools/rebar3-format.sh
Paweł Chmielowski 95a083a6f4 Replace csplit with perl in rebar3-format.sh
Bsd csplit doesn't offer some options that we require, so let's use perl
that should work everywhere
2025-06-06 16:52:28 +02:00

41 lines
896 B
Bash
Executable file

#!/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
FORMAT()
{
FPATH=$1
ERLS=$(git grep --name-only @format-begin "$FPATH"/)
for ERL in $ERLS; do
perl -n -e 'sub o { open(OUT, ">", sprintf("%s-format-%02d", $f, $n++));}; BEGIN{($f)=@ARGV;o()}; o() if /\@format-/; print OUT $_;' $ERL
done
EFMTS=$(find "$FPATH"/*-format-* -type f -exec grep --files-with-matches "@format-begin" '{}' ';')
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
}
FORMAT src
FORMAT test