Last active
September 23, 2022 16:12
-
-
Save ormaaj/7f4bc2980b624b3fdbef681b457f3890 to your computer and use it in GitHub Desktop.
builtin loader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shopt -s lastpipe extglob globstar | |
shopt -u assoc_expand_once | |
function initializeBuiltins { | |
typeset -a a | |
typeset x y z | |
set +m | |
typeset libdir=${fsRoot%%+(/)}/usr/lib64 | |
[[ -d ${libdir}/bash ]] || libdir=${rootPath%%+(/)}/lib64 | |
for x in "${libdir}"/{ctypes.so,bash/!(hello|truefalse|mypid|necho|*.*)}; do | |
if [[ $(file -b --mime-type -- "$x") == 'application/x-sharedlib' && !$? -ne 0 ]]; then | |
nm -CDj --without-symbol-versions -- "$x" | | |
while IFS= read -r y; do | |
[[ $y =~ ^(.+)_struct$ ]] || continue | |
a+=("${BASH_REMATCH[1]}") | |
done | |
(( PIPESTATUS[0] )) || enable -f "$x" -- "${a[@]}" | |
unset -v 'a[@]' | |
fi | |
done | |
for x in ln head rm stat; do | |
printf -v y %q%.s "$(type -P "$x")" "$((z=$?))" | |
let z && continue | |
eval -- \ | |
function "${x}" { command -- "$y" \"\$@\" \; } \; \ | |
function "${x}2" { builtin -- "$x" \"\$@\" \; } | |
done | |
return 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment