diff options
author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2024-06-11 08:00:45 +0200 |
---|---|---|
committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2024-06-11 08:00:45 +0200 |
commit | e4a334234b91f230571b5111a2b698230b27c660 (patch) | |
tree | 7545deca502c7ef7f676fc689f8caaeee6e19801 /templates/c/scripts | |
parent | chore(templates/rust): Quickly Update [THIS WILL BE REBASED] (diff) | |
download | flake-templates-e4a334234b91f230571b5111a2b698230b27c660.tar.gz flake-templates-e4a334234b91f230571b5111a2b698230b27c660.zip |
refactor(common): Use symlinks to state, which files should be replaced
Every symlink in the `./templates` directory is now replaced with the file it points to, making it obvious that this file should not be edited.
Diffstat (limited to 'templates/c/scripts')
l---------[-rwxr-xr-x] | templates/c/scripts/renew_copyright_header.sh | 93 |
1 files changed, 1 insertions, 92 deletions
diff --git a/templates/c/scripts/renew_copyright_header.sh b/templates/c/scripts/renew_copyright_header.sh index 4f424c3..70917db 100755..120000 --- a/templates/c/scripts/renew_copyright_header.sh +++ b/templates/c/scripts/renew_copyright_header.sh @@ -1,92 +1 @@ -#! /usr/bin/env sh - -# NOTE: This is the line length of the .licensure.yml header template **plus** the extra -# line after the template comment. -TEMPLATE_LINE_LENGTH=20 -LATEX_TEMPLATE_LINE_LENGTH=9 - -PROJECT_ROOT="$(git rev-parse --show-toplevel)" - -remove() { - extension="$1" - file="$2" - - # 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 $TEMPLATE_LINE_LENGTH lines long) - "Makefile" | "toml" | "envrc" | "yml" | "gitignore" | "awk") - sed --in-place "1,${TEMPLATE_LINE_LENGTH}d" "$file" - ;; - # LaTeX files (or TeX files in general) have a different license, use the - # $LATEX_TEMPLATE_LINE_LENGTH variable. - "tex") - sed --in-place "1,${LATEX_TEMPLATE_LINE_LENGTH}d" "$file" - ;; - # normal '/* ... */' like comments (these are $TEMPLATE_LINE_LENGTH + 2 lines long) - "c" | "h" | "md" | "rs") - length="$((TEMPLATE_LINE_LENGTH + 2))" - sed --in-place "1,${length}d;" "$file" - ;; - # alejandra (the nix formatter) removes the blank line after the comment, - # thus only $TEMPLATE_LINE_LENGTH - 1 lines - "nix") - length="$((TEMPLATE_LINE_LENGTH - 1))" - sed --in-place "1,${length}d;" "$file" - ;; - # Shell needs a shebang on the first line, only after the first line can we - # remove the $TEMPLATE_LINE_LENGTH lines - "sh") - sed --in-place "2,${TEMPLATE_LINE_LENGTH}d;" "$file" - licensure --in-place "$file" - - TEMPLATE_LINE_LENGTH_NEW="$(($(yq --raw-output '.licenses | map(.template) | join("")' "$PROJECT_ROOT/.licensure.yml" | wc -l) + $(yq '.comments | last | .commenter.trailing_lines' "$PROJECT_ROOT/.licensure.yml")))" - - # delete the current shebang - to="$((TEMPLATE_LINE_LENGTH_NEW + 1))" - sed --in-place "${TEMPLATE_LINE_LENGTH_NEW},${to}d;" "$file" - - # add a new one - sed --in-place "1i#! /usr/bin/env sh" "$file" - ;; - *) - echo "File '$file' with extension '$extension' is not know yet, please add it!" - ;; - esac -} - -list() { - echo "$extension -> $file" -} - -if [ -f "$1" ]; then - file="$(realpath "$1")" - filename="$(basename -- "$file")" - extension="${filename##*.}" - filename="${filename%.*}" - - if [ -n "$DRY_RUN" ]; then - list "$extension" "$file" - else - remove "$extension" "$file" - fi -else - fd --type file --hidden . | while read -r file; do - if grep --quiet 'SPDX-License-Identifier' "$file"; then - filename="$(basename -- "$file")" - extension="${filename##*.}" - filename="${filename%.*}" - - if [ -n "$DRY_RUN" ]; then - list "$extension" "$file" - else - remove "$extension" "$file" - fi - fi - done - - if [ -z "$DRY_RUN" ]; then - licensure --in-place --project - nix fmt - fi -fi +../../../common/files/scripts/renew_copyright_header.sh \ No newline at end of file |