diff options
author | Wojtek Kosior <koszko@koszko.org> | 2021-11-30 19:31:49 +0100 |
---|---|---|
committer | Wojtek Kosior <koszko@koszko.org> | 2021-11-30 19:32:21 +0100 |
commit | 6106c789ee818fd18240fd3f99eead598406852f (patch) | |
tree | f575e45b7872b7f85b33210db5e01caf7572c615 /shell_utils.sh | |
parent | 5b2a7a61fd5cf9982f105a3081c2ed7a298b71df (diff) | |
download | browser-extension-6106c789ee818fd18240fd3f99eead598406852f.tar.gz browser-extension-6106c789ee818fd18240fd3f99eead598406852f.zip |
rewrite parts of build script in awk
Diffstat (limited to 'shell_utils.sh')
-rw-r--r-- | shell_utils.sh | 25 |
1 files changed, 6 insertions, 19 deletions
diff --git a/shell_utils.sh b/shell_utils.sh index 5fd24ff..6d4cc76 100644 --- a/shell_utils.sh +++ b/shell_utils.sh @@ -3,21 +3,8 @@ # This file is meant to be sourced in sh. -ENDL=" -" - -# A "raw" echo, interprets neither backclash escapes nor command-line options. -# Does not emit trailing newline. -ech() { - printf %s "$*" -} - -errcho() { - echo "$@" >&2 -} - map_set_instr() { - echo "$1__$2='$3'" + printf "%s__%s='%s'" "$1" "$2" "$3" } map_set() { @@ -29,11 +16,11 @@ map_set_export() { } map_get() { - eval "echo \"\$$1__$2\"" + eval "printf %s \"\$$1__$2\"" } map_del_instr() { - echo "unset $1__$2" + printf 'unset %s__%s' "$1" "$2" } map_del() { @@ -41,18 +28,18 @@ map_del() { } sanitize() { - echo "$1" | tr /.- _ + printf %s "$1" | tr /.- _ } escape_regex_special() { - ech "$1" | sed 's/\([]\.*?{},()[-]\)/\\\1/g' + printf %s "$1" | sed 's/\([]\.*?{},()[-]\)/\\\1/g' } # Note: We don't actually parse JSON. We extract needed keys with sed regexes # which does not work in the general case but is sufficient for now. get_json_key() { local KEY_REG="$(escape_regex_special "$1")" - ech "$2" | + printf %s "$2" | sed 's/\(.*"'"$KEY_REG"'"[[:space:]]*:[[:space:]]*"\([^"]*\)"\)\?.*/\2/' | grep . | head -1 } |