aboutsummaryrefslogtreecommitdiff
path: root/shell_utils.sh
diff options
context:
space:
mode:
Diffstat (limited to 'shell_utils.sh')
-rw-r--r--shell_utils.sh13
1 files changed, 13 insertions, 0 deletions
diff --git a/shell_utils.sh b/shell_utils.sh
index 30dfead..5fd24ff 100644
--- a/shell_utils.sh
+++ b/shell_utils.sh
@@ -43,3 +43,16 @@ map_del() {
sanitize() {
echo "$1" | tr /.- _
}
+
+escape_regex_special() {
+ ech "$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" |
+ sed 's/\(.*"'"$KEY_REG"'"[[:space:]]*:[[:space:]]*"\([^"]*\)"\)\?.*/\2/' |
+ grep . | head -1
+}