about summary refs log tree commit diff stats
path: root/common
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-10-04 16:40:48 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-10-04 16:40:48 +0200
commitb2d6005a8c62e88d26607329ab2831d2346d010b (patch)
treee0345230c01f14de67fb511ab69231c67bcb3054 /common
parentchore(version): v0.8.0 (diff)
downloadflake-templates-b2d6005a8c62e88d26607329ab2831d2346d010b.tar.gz
flake-templates-b2d6005a8c62e88d26607329ab2831d2346d010b.zip
fix(common/init): Correctly quote inputted text
Diffstat (limited to 'common')
-rw-r--r--common/init9
1 files changed, 8 insertions, 1 deletions
diff --git a/common/init b/common/init
index e8f72c8..35662e2 100644
--- a/common/init
+++ b/common/init
@@ -30,6 +30,13 @@ die() {
     printf "init: ERROR: %s\n" "$1"
     exit 1
 }
+quotify() {
+    input="$1"
+
+    # The quotes are actually fine like they are.
+    # shellcheck disable=SC1003
+    echo "$input" | awk '{ gsub(/'\''/, "'\''\\'\'''\''", $0); print("'\''" $0 "'\''"); }'
+}
 
 # Prompt the user for a specific variable.
 # ## Args:
@@ -57,7 +64,7 @@ prompt() {
         LE "> " 0 " " "$pr_suggested_answer" ""
     fi
 
-    pr_new_variable="$(printf '%s="%s"' "$pr_variable_upper" "$REPLY")"
+    pr_new_variable="$(printf '%s=%s' "$pr_variable_upper" "$(quotify "$REPLY")")"
 
     eval "$pr_new_variable"
     printf "%s\n" "$pr_new_variable" >>"$replacement_file"