aboutsummaryrefslogtreecommitdiffstats
path: root/common/init
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-04-02 13:19:32 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-04-02 13:24:36 +0200
commitc800a8a50092df687f338fe8c48fb158ffd15210 (patch)
tree8aa4657595ac1c3528ffe0180f71051448b0befc /common/init
parentbuild(update_common_files): Allow to specify which file to move where (diff)
downloadflake-templates-c800a8a50092df687f338fe8c48fb158ffd15210.zip
fix(common): Remove the last occurrences of hard coded values
Diffstat (limited to '')
-rwxr-xr-xcommon/init41
1 files changed, 27 insertions, 14 deletions
diff --git a/common/init b/common/init
index 787b663..1b7c86b 100755
--- a/common/init
+++ b/common/init
@@ -5,33 +5,40 @@
replacement_file="$(mktemp)"
trap cleanup INT
-trap "cleanup; remove" EXIT
+trap "cleanup; remove_self" EXIT
cleanup() {
rm "$replacement_file"
}
-remove() {
+remove_self() {
rm "$(realpath "$0")"
rm "$(realpath "$(dirname "$0")")/shell_line_editor.sh"
- git add .
}
-# Prompt the user for a specific variable. The variable is the first
-# input, the second is an optional description.
-# The third argument can be a suggested answer, already pre populated.
+# 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"
- 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"
+ if [ -n "$pr_ask" ]; then
+ REPLY="$pr_suggested_answer";
else
- printf ":\n"
- fi
+ 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" ""
+ # 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")"
@@ -43,7 +50,10 @@ 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)" "$(basename "$PWD" | sed 's/\([a-z]\)/\u\1/')"
+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 "The capitalized name of the application (for documentation)" "$(echo "$APPLICATION_NAME" | sed 's/\([a-z]\)/\U\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)"
@@ -54,6 +64,8 @@ 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"
@@ -68,4 +80,5 @@ while read -r var; do
fd . --hidden --type file --exec sed --in-place "s|%\bINIT_$var_name\b|$var_value|"
done < "$replacement_file"
+
# vim: ft=sh