Created
March 14, 2023 13:20
-
-
Save ormaaj/b4690e6df66b87f8fde7c655e21c6175 to your computer and use it in GitHub Desktop.
generate modified builtins
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
#!/bin/bash | |
shopt -s extglob lastpipe expand_aliases | |
shopt -u assoc_expand_once | |
BASH_COMPAT=51 | |
typeset -a bool=([1]=) | |
function unset2 { command unset "$@"; } | |
function mkTranslucentFunctions { | |
typeset -a builtins | |
typeset func | |
compgen -A builtin | mapfile -t builtins | |
alias 'function=function ' | |
for func in "${builtins[@]}"; do | |
alias "tfunc=t${func}" | |
. /proc/self/fd/3 3<<-\EOF | |
function tfunc { fn= command ${bool[1${fn+-1}]+'eval'} unset2 -v fn \; "${FUNCNAME#t}" '"$@"' '&&' return "$?"; } | |
EOF | |
done | |
unalias function | |
} | |
mkTranslucentFunctions | |
#typeset -fp | |
tfalse; echo "$?" | |
(exit 2); ttrue; echo "$?" | |
(exit 3); techo 1 2 3; echo "$?" | |
(exit 4); tprintf -v fn '%s ' "${BASH_COMMAND}:" 1 2 3; echo "${fn}${?}" | |
# vim: set ft=bash fenc=utf-8 ff=unix ts=4 noet : |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment