diff options
author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2024-10-04 17:53:15 +0200 |
---|---|---|
committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2024-10-04 17:53:15 +0200 |
commit | 7c0de8b77d1b1f0a0ea512d29781df558c664b6c (patch) | |
tree | 0b2f87146900e87d8757d07d474bf5240647da83 /common | |
parent | fix(templates/rust/Cargo.toml): Fix typos in `%INIT_` variables (diff) | |
download | flake-templates-7c0de8b77d1b1f0a0ea512d29781df558c664b6c.tar.gz flake-templates-7c0de8b77d1b1f0a0ea512d29781df558c664b6c.zip |
refactor(common/init): Rewrite the `quotify` function in python
The AWK version was getting confused with newlines (`\n`) in the input.
Diffstat (limited to 'common')
-rw-r--r-- | common/init | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/common/init b/common/init index 35662e2..4298e68 100644 --- a/common/init +++ b/common/init @@ -31,11 +31,14 @@ die() { exit 1 } quotify() { - input="$1" - - # The quotes are actually fine like they are. - # shellcheck disable=SC1003 - echo "$input" | awk '{ gsub(/'\''/, "'\''\\'\'''\''", $0); print("'\''" $0 "'\''"); }' + python -c " +import sys +if len(sys.argv) > 1: + text =''.join(sys.argv[1:]) +else: + text = sys.stdin.read() +quoted_text = text.replace(\"'\", \"'\\\\''\") +print(f\"'{quoted_text}'\", end='')" "$@" } # Prompt the user for a specific variable. @@ -80,6 +83,8 @@ require mv require sed require chmod +require python + # 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/[_-]/ /g' | sed 's/^\(\w\)/\U\1/g' | sed 's/ \(\w\)/ \U\1/g')" |