forked from chr15m/flk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extras.sh
62 lines (51 loc) · 1.33 KB
/
extras.sh
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
_str_replace () {
local s="${ANON["${1}"]}"; shift
local f="${ANON["${1}"]}"; shift
local x="${ANON["${1}"]}"; shift
_string "${s//${f}/${x}}"
}
_fref "str-replace" _str_replace
_str_split() {
local var="${ANON["${1}"]}"; shift
local ifs="${ANON["${1}"]}"; shift
_list
local newlist="${r}"
while IFS="${ifs}" read -ra _str_split_arr; do
for _str_split_itm in "${_str_split_arr[@]}"; do
_string "${_str_split_itm}";
_conj! "${newlist}" "${r}";
done
done <<< "${var}"
r="${newlist}"
}
_fref "str-split" _str_split
_env() {
local key
local val
[ "${1}" != "" ] && key="${ANON["${1}"]}"; shift
[ "${1}" != "" ] && val="${ANON["${1}"]}"; shift
[ "${val}" != "" ] && export "${key}=${val}"
local line
local ikey
local ival
_hash_map; local envmap="${r}"
while read -r -d '' line; do
IFS='=' read ikey ival <<< "${line}"
_string "${ival}"
_assoc! "${envmap}" "${ikey}" "${r}"
done < <(env -0)
if [ "${key}" != "" ]
then
_get "${envmap}" "${key}"
[[ "${r}" ]] || r="${__nil}"
else
r="${envmap}"
fi
}
_fref "env" _env
_remove_hashbang() {
src="${ANON["${1}"]}"
_string "${src/*flk$'\n'/}"
}
_fref "remove-hashbang" _remove_hashbang
REP "(def! load-file-without-hashbang (fn* (f) (eval (read-string (str \"(do \" (remove-hashbang (slurp f) ) \"\nnil)\")))))"