Skip to content

Instantly share code, notes, and snippets.

@ormaaj
Created March 14, 2023 13:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ormaaj/b4690e6df66b87f8fde7c655e21c6175 to your computer and use it in GitHub Desktop.
Save ormaaj/b4690e6df66b87f8fde7c655e21c6175 to your computer and use it in GitHub Desktop.
generate modified builtins
#!/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