Skip to content

Instantly share code, notes, and snippets.

@ormaaj
Last active September 23, 2022 16:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ormaaj/7f4bc2980b624b3fdbef681b457f3890 to your computer and use it in GitHub Desktop.
Save ormaaj/7f4bc2980b624b3fdbef681b457f3890 to your computer and use it in GitHub Desktop.
builtin loader
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