Skip to content

Commit 2ffe290

Browse files
committed
Switch to bash 4.4+ branch of bashup.events
1 parent bf51fd2 commit 2ffe290

File tree

2 files changed

+24
-28
lines changed

2 files changed

+24
-28
lines changed

.dkrc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33
dk use: cram # run tests using the "cram" functional test tool
44
dk use: modd-watch # watch files and re-run tests or other commands
55
dk use: shell-console # make the "console" command enter a subshell
6-
dk use: bash32
76
dk use: shellcheck
87

98
# Define overrides, new commands, functions, etc. here:
109

11-
for f in bashup.events mdsh jqmd loco realpaths; do
12-
require $f basher install bashup/${f#bashup.}
13-
done
10+
bashup-require() { for REPLY; do require "$REPLY" basher install bashup/"$REPLY"; done ; }
11+
12+
bashup-require mdsh jqmd loco realpaths
13+
14+
# get the bash 4.4 branch, since doco is 4.4+
15+
require bashup.events github bashup/events bash44 bashup.events
1416

1517

1618
# SC1090 = dynamic 'source' command

bin/doco

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -533,42 +533,36 @@ include() {
533533
fi
534534
}
535535
#!/usr/bin/env bash
536+
# shellcheck disable=2016,2034,2059,2128,2145
537+
{ declare -gA bashup_ev bashup_ev_r
536538
event(){ case $1 in error|quote|encode|decode);; *)
537-
__ev.encode "${2-}";local f n='' e=bashup_event_$REPLY;f=${e/event/flag}
538-
case $1 in emit) shift;${!f-};eval "${!e-}"; return ;;on|once|off|has)
539+
local n='' s=${2:-_};local -n e=bashup_ev["$s"] f=bashup_ev_r["$s"]
540+
case $1 in emit) shift;${f-}||return;eval "${e-}";return;; on|once|off|has)
539541
case "${3-}" in @_) n='$#';; @*[^0-9]*);; @[0-9]*) n=$((${3#@}));; esac; ${n:+
540542
set -- "$1" "$2" "${@:4}" }
541543
case $1/$# in
542-
has/[12]) REPLY=;; */[12]) set -- error "${2-}: missing callback";;
544+
has/[12]) REPLY=;; */[12]) set -- error "${2:-}: missing callback";;
543545
*) __ev.quote "${@:3}";((${n/\$#/1}))&&REPLY+=' "${@:2:'"$n"'}"';REPLY+=$'\n'
544546
esac
545547
esac
546548
esac ;__ev."$@";}
547549
__ev.error(){ echo "$1">&2;return "${2:-64}";}
548-
__ev.quote(){ REPLY=; ${@+printf -v REPLY ' %q' "$@"}; REPLY=${REPLY# };}
549-
__ev.has(){ [[ ${!e-} && $'\n'"${!e}" == *$'\n'"$REPLY"* && ! ${!f-} ]];}
550-
__ev.on(){ __ev.has && return;if [[ ! ${!f-} ]];then eval "$e"+='$REPLY';else eval "${!e-};$REPLY";fi;}
551-
__ev.off(){ __ev.has||return 0; n="${!e}"; n=${n#"$REPLY"}; eval "$e"=$'"${n//\n"$REPLY"/\n}"';}
552-
__ev.fire(){ ${!f-};set -- "$e" "${@:2}"; while [[ ${!1-} ]];do eval "$1=;${!1}"; done ;}
553-
__ev.all(){ ${!f-};e=${!e-};eval "${e//$'\n'/||return; }";}
554-
__ev.any(){ ${!f-};e=${!e-};eval "${e//$'\n'/&&return|| } ! :";}
555-
__ev.resolve(){
556-
${!f-};__ev.fire "$@";__ev.quote "$@"
557-
readonly "$f=eval __ev.error 'event \"'$1'\" already resolved' 70;return" "$e=set -- $REPLY"
558-
}
559-
__ev.resolved(){ [[ ${!f-} ]];}
550+
__ev.quote(){ REPLY=("${*@Q}");}
551+
__ev.has(){ [[ ${e-} && $'\n'"$e" == *$'\n'"$REPLY"* && ! ${f-} ]];}
552+
__ev.on(){ __ev.has&&return;if [[ ! ${f-} ]];then e+="$REPLY";else eval "${e-};$REPLY";fi;}
553+
__ev.off(){ __ev.has||return 0;n="${e#"$REPLY"}";e="${n//$'\n'"$REPLY"/$'\n'}";}
554+
__ev.fire(){ ${f-}||return;set -- "$s" "${@:2}";while [[ ${bashup_ev["$1"]-} ]];do eval 'bashup_ev["$1"]=;'"${bashup_ev["$1"]}";done;}
555+
__ev.all(){ ${f-}||return;n=${e-};eval "${n//$'\n'/||return;}";}
556+
__ev.any(){ ${f-}||return;n=${e-};eval "${n//$'\n'/&&return|| } ! :";}
557+
__ev.resolve(){ ${f-}||return;__ev.fire "$@";__ev.quote "$@";bashup_ev_r["$1"]=__ev_already;bashup_ev["$1"]="set -- $REPLY";}
558+
__ev_already() { __ev.error "event \"$s\" already resolved" 70;}
559+
__ev.resolved(){ [[ ${f-} ]];}
560560
__ev.once(){ n=${n:-0} n=${n/\$#/_}; event on "$1" "@$n" __ev_once $# "@$n" "$@";}
561561
__ev_once(){ event off "$3" "$2" __ev_once "${@:1:$1+2}"; "${@:4}";}
562-
__ev_jit(){
563-
local r=${__ev_jit-} s=$1;((${#r}<250))||__ev_jit=
564-
while [[ "$s" ]]; do
565-
r=${s::1};s=${s//$r/};printf -v r 'REPLY=${REPLY//%q/_%02x};' "$r" "'$r";eval "$r";__ev_jit+=$r
566-
done
567-
eval '__ev.encode(){ local LC_ALL=C;REPLY=${1//_/_5f};'\
568-
"${__ev_jit-}"' [[ $REPLY != *[^_[:alnum:]]* ]] || __ev_jit "${REPLY//[_[:alnum:]]/}";}'
569-
};__ev_jit ''
562+
__ev.encode(){ local LC_ALL=C;n=${1//[![:alnum:]]/_%02x};s=${1//[[:alnum:]]};[[ $s =~ ${s//?/(.)} ]];set -- "${BASH_REMATCH[@]:1}";printf -v REPLY "$n" "${@/#/\'}";}
570563
__ev.decode(){ REPLY=();while (($#));do printf -v REPLY[${#REPLY[@]}] %b "${1//_/\\x}";shift;done;}
571-
__ev.list(){ eval 'set -- "${!'"$e"'@}"';__ev.decode "${@#bashup_event_}";}
564+
__ev.list(){ REPLY=("${!bashup_ev[@]}");[[ $1 ]]||return 0;s=$1;set -- "${REPLY[@]}";REPLY=();for n;do [[ $n == "$s"* ]]||continue;REPLY+=("$n");done;}
565+
}
572566
is-target-name() { [[ $1 && $1 != *[^-._A-Za-z0-9]* ]]; }
573567
574568
target() {

0 commit comments

Comments
 (0)