aboutsummaryrefslogtreecommitdiff
path: root/shell_utils.sh
blob: 6d4cc763dc6422e304e52f607d22962b5af8146a (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# Copyright (C) 2021 Wojtek Kosior
# Redistribution terms are gathered in the `copyright' file.

# This file is meant to be sourced in sh.

map_set_instr() {
    printf "%s__%s='%s'" "$1" "$2" "$3"
}

map_set() {
    eval "$(map_set_instr "$@")"
}

map_set_export() {
    eval "export $(map_set_instr "$@")"
}

map_get() {
    eval "printf %s \"\$$1__$2\""
}

map_del_instr() {
    printf 'unset %s__%s' "$1" "$2"
}

map_del() {
    eval "$(map_del_instr "$@")"
}

sanitize() {
    printf %s "$1" | tr /.- _
}

escape_regex_special() {
    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")"
    printf %s "$2" |
	sed 's/\(.*"'"$KEY_REG"'"[[:space:]]*:[[:space:]]*"\([^"]*\)"\)\?.*/\2/' |
	grep . | head -1
}
2 23:51:38 -0500'>2023-02-02.dir-locals.el: Adjust indentation rule for test-assertm....Maxim Cournoyer 2023-02-02.dir-locals.el: Add indentation rule for computed-file....Maxim Cournoyer 2022-09-07.dir-locals.el: Update yas snippets directory....Andrew Tropin 2022-09-05.dir-locals.el: Add .go to completion-ignored-extensions....Andrew Tropin 2022-09-05.dir-locals.el: Add guix yasnippets....Andrew Tropin 2022-07-10monads: Add 'mparameterize'....Ludovic Courtès 2022-07-10.dir-locals.el: Restore Emacs 27 lisp-fill-paragraph behavior....Maxim Cournoyer 2022-06-28.dir-locals.el: Properly indent 'wrap-script'....Maxim Cournoyer 2022-06-07.dir-locals: Adjust to bug-reference-mode in Emacs 28....Ludovic Courtès 2022-03-06import: github: Reuse HTTP connection for the /tags URL fallback....Ludovic Courtès 2022-03-06tests: Add (guix http-client) tests....Ludovic Courtès 2022-01-29.dir-locals.el: Don't mess up indentation of prepend and append....Liliana Marie Prikler 2021-08-12Merge branch 'master' into core-updates-frozen...Marius Bakke 2021-08-02.dir-locals.el: Specify indentation rule for with-shepherd-action....Maxim Cournoyer 2021-07-18Merge branch 'master' into core-updatesLudovic Courtès 2021-07-11packages: Add 'modify-inputs'....Ludovic Courtès 2021-06-29pack: Add support for the deb format....Maxim Cournoyer 2021-03-30build-system: Rewrite using gexps....Ludovic Courtès