-
Notifications
You must be signed in to change notification settings - Fork 1
/
lib.tools
71 lines (61 loc) · 1.31 KB
/
lib.tools
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
63
64
65
66
67
68
69
70
71
#!bin/bash
function strlist_add() {
local l_varName=$1; shift;
local l_varValue="${!l_varName}"
local c_var;
for c_var in "$@"; do
if [ ! -z "${l_varValue}" ]; then
l_varValue="${l_varValue};"
fi
l_varValue="${l_varValue}${c_var}"
done
eval ${l_varName}=\"${l_varValue}\"
}
function decorate_builtin() {
local p_fn=$1; shift
local p_pre=$1; shift
local p_post=$1; shift
if [ ! -z "${p_pre}" ]; then
p_pre="${p_pre} \"\$@\";"
fi
if [ ! -z "${p_post}" ]; then
p_post="${p_post} \"\$@\";"
fi
local l_tmp=$(mktemp)
cat - > ${l_tmp} <<EOF
function ${p_fn} () {
local ret=0;
${p_pre}
if [ \$? -eq 0 ]; then
builtin ${p_fn} "\$@";
ret=\$?;
fi;
${p_post}
return "\$ret";
}
EOF
local l_data=$(cat ${l_tmp})
rm -f ${l_tmp}
eval "${l_data}"
}
# function decorate_function() {
# local p_fn=$1; shift
# local p_pre=$1; shift
# local p_post=$1; shift
# if [ ! -z "${p_pre}" ]; then
# p_pre="${p_pre} \"\$@\";"
# fi
# if [ ! -z "${p_post}" ]; then
# p_post="${p_post} \"\$@\";"
# fi
# eval "
# _inner_$(typeset -f "${p_fn}")
# ${p_fn}"'() {
# '"${p_pre}"'
# _inner_'"${p_fn}"' "$@"
# local ret=$?
# '"${p_post}"'
# return "$ret"
# }'
# export ${p_fn}_decorates="_${l_guid}_${p_fn}"
# }