This repository has been archived on 2024-05-26. You can view files and clone it, but cannot push or open issues or pull requests.
trixy/scripts/renew_copyright_header.sh

44 lines
1.5 KiB
Bash
Raw Normal View History

#! /usr/bin/env sh
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
licensure --in-place --project