From e4a334234b91f230571b5111a2b698230b27c660 Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Tue, 11 Jun 2024 08:00:45 +0200 Subject: 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. --- templates/awk/init | 97 +----------------------------------------------------- 1 file changed, 1 insertion(+), 96 deletions(-) mode change 100755 => 120000 templates/awk/init (limited to 'templates/awk/init') diff --git a/templates/awk/init b/templates/awk/init deleted file mode 100755 index b9b4f80..0000000 --- a/templates/awk/init +++ /dev/null @@ -1,96 +0,0 @@ -#!/usr/bin/env sh - -. "$(realpath "$(dirname "$0")")/shell_line_editor.sh" - -replacement_file="$(mktemp)" - -trap cleanup INT -trap "cleanup; remove_self" EXIT -cleanup() { - rm "$replacement_file" -} -remove_self() { - rm "$(realpath "$0")" - rm "$(realpath "$(dirname "$0")")/shell_line_editor.sh" -} - -# Prompt the user for a specific variable. -# ## Args: -# [1]: Name of the variable to populate the answer to -# [2]: An optional description -# [3]: An optionally suggested answer -# [4]: If this is set, the user is not even asked. -prompt() { - pr_variable_upper="$(echo "$1" | sed 's/\([a-z]\)/\U\1/')" - pr_description="$2" - pr_suggested_answer="$3" - pr_ask="$4" - - if [ -n "$pr_ask" ]; then - REPLY="$pr_suggested_answer"; - else - printf "\033[94;1mEnter %s\033[0m" "$pr_variable_upper" - if [ -n "$pr_description" ];then - printf " (\033[93;1m%s\033[0m):\n" "$pr_description" - else - printf ":\n" - fi - - # LE "> " 0 " " "$pr_suggested_answer" "yes_please_produce_debug_output" - LE "> " 0 " " "$pr_suggested_answer" "" - fi - - pr_new_variable="$(printf '%s="%s"' "$pr_variable_upper" "$REPLY")" - - eval "$pr_new_variable" - printf "%s\n" "$pr_new_variable" >> "$replacement_file" -} - -git init - -# necessary meta data -prompt APPLICATION_NAME "The name of the application" "$(basename "$PWD")" -prompt APPLICATION_NAME_STYLIZED "The stylized name of the application (for documentation)" "$(echo "$APPLICATION_NAME" | sed 's/\([a-z]*\)/\u\1/')" -prompt APPLICATION_NAME_CAPITALIZED_MAN_PART "The capitalized name of the application (for documentation also with a man section part)" "$(echo "$APPLICATION_NAME" | sed 's/\([a-z]*\)/\U\1(1)/')" "dont_ask" -prompt APPLICATION_VERSION "The version of this program, without the prefix" "0.1.0" - -prompt AUTHOR_NAME "The name of the author (or authors)" "$(git config --get user.name)" -prompt AUTHOR_EMAIL "The email of the author (or authors)" "$(git config --get user.email)" - -# cog change-log variables -prompt REMOTE "The remote, this project will be pushed to" "codeberg.org" -prompt REPOSITORY "The name of the repository in the remote" "$APPLICATION_NAME" -prompt OWNER "The name of owner of the repository" "$AUTHOR_NAME" - -# nice meta data -prompt DESCRIPTION "The description of this project" "[can be empty]" -prompt CURRENT_DATE "The stylized version of the current date" "$(date +'%b %Y')" -prompt YEAR "The year the work on this has begun (for copyright reasons)" "$(date +'%Y')" - -# LICENSE.spdx data (source: https://github.com/david-a-wheeler/spdx-tutorial) -prompt APPLICATION_ORIGINATOR "The person or organization from whom the package originally came" "$AUTHOR_NAME" -prompt APPLICATION_HOME_PAGE "The package's home page URL" "https://$REMOTE/$OWNER/$REPOSITORY" - -echo "$DESCRIPTION" > .git/description - -while read -r var; do - var_name="${var%=*}" - var_value="${var#*=\"}" - var_value="${var_value%\"}" - - fd . --hidden --type file --exec sed --in-place "s|%\bINIT_$var_name\b|$var_value|g" - - # Replace the variable in file paths - fd "%INIT_$var_name" . --hidden | while read -r file_path; do - new_file_path="$(echo "$file_path" | sed "s|%INIT_$var_name|$var_value|g")"; - mv "$file_path" "$new_file_path" - done -done < "$replacement_file" - -# HACK: Re-add the executable permissions to files, which the nix template has somehow -# removed <2024-04-02> -chmod +x scripts/* -chmod +x update.sh -[ -f ./build.sh ] && chmod +x build.sh - -# vim: ft=sh diff --git a/templates/awk/init b/templates/awk/init new file mode 120000 index 0000000..2daec78 --- /dev/null +++ b/templates/awk/init @@ -0,0 +1 @@ +../../common/files/init \ No newline at end of file -- cgit 1.4.1