aboutsummaryrefslogtreecommitdiff
path: root/shell_utils.sh
diff options
context:
space:
mode:
authorjahoti <jahoti@tilde.team>2021-12-02 00:00:00 +0000
committerjahoti <jahoti@tilde.team>2021-12-02 00:00:00 +0000
commit6d819aaea70756b778e71478ec6ce40a8d680841 (patch)
tree1acb322aba177da95095f50ddbb43a993824de86 /shell_utils.sh
parent263d03d5a0b85874e988c9ea7373f9f9471ef1be (diff)
parent69e53743393664ed2db59bbe9bbeaf6f124754f3 (diff)
downloadbrowser-extension-6d819aaea70756b778e71478ec6ce40a8d680841.tar.gz
browser-extension-6d819aaea70756b778e71478ec6ce40a8d680841.zip
Merge remote-tracking branch 'origin/koszko' into build-sys
Diffstat (limited to 'shell_utils.sh')
-rw-r--r--shell_utils.sh25
1 files changed, 6 insertions, 19 deletions
diff --git a/shell_utils.sh b/shell_utils.sh
index 74d1436..51361f5 100644
--- a/shell_utils.sh
+++ b/shell_utils.sh
@@ -11,21 +11,8 @@
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# CC0 1.0 Universal License for more details.
-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() {
@@ -37,11 +24,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() {
@@ -49,18 +36,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
}