-
Notifications
You must be signed in to change notification settings - Fork 1
/
lib.cdevent
62 lines (54 loc) · 1.36 KB
/
lib.cdevent
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
#!/bin/bash
export CDEVENT_CMDS=""
export CDEVENT_CMDS_PRE=""
function cdevent_push_pre() {
local l_cmd="$1"; shift
if [ ! -z "${CDEVENT_CMDS_PRE}" ]; then
CDEVENT_CMDS_PRE="${CDEVENT_CMDS_PRE};"
fi
CDEVENT_CMDS_PRE="${CDEVENT_CMDS_PRE}${l_cmd}"
}
function cdevent_push() {
local l_cmd="$1"; shift
if [ ! -z "${CDEVENT_CMDS}" ]; then
CDEVENT_CMDS="${CDEVENT_CMDS};"
fi
CDEVENT_CMDS="${CDEVENT_CMDS}${l_cmd}"
}
function __cdevent_run_pre() {
local l_args="$*"
local l_list="${CDEVENT_CMDS_PRE}"
local l_ret=0
if [ ! -z "${l_list}" ]; then
l_list="${l_list};"
fi
while read -r -d ";" cmd; do
eval "${cmd} \"${l_args}\"" || {
l_ret=1
}
done < <(echo "${l_list}")
return ${l_ret}
}
function __cdevent_run() {
local l_args="$*"
local l_list="${CDEVENT_CMDS}"
local l_ret=0
if [ ! -z "${l_list}" ]; then
l_list="${l_list};"
fi
# transform cmds string into array to avoid redirecting
# when running individual commands (see tty -s in lib.envloader)
declare -a l_cmds=() || return
while read -r -d ";" cmd; do
l_cmds+=( $cmd )
done < <(echo "${l_list}")
# loop cmds without redirecting (see tty -s in lib.envloader)
for cmd in "${l_cmds[@]}"; do
eval "${cmd} \"${l_args}\"" || {
l_ret=1
break
}
done
return ${l_ret}
}
decorate_builtin cd __cdevent_run_pre __cdevent_run