fix(scripts/renew_copyright_header): Add per filetype handling
Otherwise, the mistakes are not avoidable.
This commit is contained in:
parent
a653dec211
commit
3484ead8af
|
@ -1,6 +1,42 @@
|
|||
#! /usr/bin/env sh
|
||||
|
||||
fd --type file . | xargs grep 'The Trinitrix Project <soispha@vhack.eu, antifallobst@systemausfall.org>' | awk 'BEGIN{ FS=":"} {print $1}' | xargs sed -i '20s|*/||; 1,19d'
|
||||
TEMPLATE_LINE_LENGHT=19
|
||||
|
||||
fd --type file . | while read -r file; do
|
||||
if grep --quiet 'The Trinitrix Project <soispha@vhack.eu, antifallobst@systemausfall.org>' "$file"; then
|
||||
filename="$(basename -- "$file")"
|
||||
extension="${filename##*.}"
|
||||
filename="${filename%.*}"
|
||||
|
||||
# We need to differentiate, when removing the old copyright header, as some
|
||||
# formatters do weird things to the file
|
||||
case "$extension" in
|
||||
# normal '#' comments (these are 19 lines long)
|
||||
"Makefile" | "toml")
|
||||
sed --in-place "1,${TEMPLATE_LINE_LENGHT}d" "$file"
|
||||
;;
|
||||
# normal '/* ... */' like comments (these are 21 lines long--'#' + 2)
|
||||
"c" | "ebnf" | "h" | "md" | "rs" | "tri")
|
||||
lenght="$((TEMPLATE_LINE_LENGHT + 2))"
|
||||
sed --in-place "1,${lenght}d;" "$file"
|
||||
;;
|
||||
# alejandra (the nix formatter) removes the blank line after the comment,
|
||||
# thus only 18 lines
|
||||
"nix")
|
||||
lenght="$((TEMPLATE_LINE_LENGHT - 1))"
|
||||
sed --in-place "1,${lenght}d;" "$file"
|
||||
;;
|
||||
# Shell needs a shebang on the first line, only after the first line can we
|
||||
# remove the 19 lines
|
||||
"sh")
|
||||
sed --in-place "2,${TEMPLATE_LINE_LENGHT}d;" "$file"
|
||||
;;
|
||||
*)
|
||||
echo "File '$file' with extension '$extension' is not know yet, please add it!"
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
done
|
||||
|
||||
nix fmt
|
||||
|
||||
|
|
Reference in New Issue