Created
June 2, 2025 07:22
-
-
Save varqox/70565e32025dd3dfec2cc53542a2bd8f to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
#set -exuo pipefail | |
shopt -s expand_aliases | |
function safe_function { | |
echo "$@" | |
echo "sf: ${BASH_LINENO[0]}" | |
sed -n "${BASH_LINENO[0]},/^}/p" "${BASH_SOURCE[1]}" | |
} | |
alias safe_function=' | |
__safe_function_line="${LINENO}" | |
__safe_function_name="$(sed -n "${__safe_function_line}s/\s*safe_function\s\+\(\(\w\|-\|_\)\+\).*/\1/p" < "${BASH_SOURCE[0]}")" && | |
function __safe_function { #' | |
alias end_safe_function='} && | |
eval "function $__safe_function_name { | |
echo done | |
}"' | |
safe_function x-y_z: | |
echo xyz | |
echo $@ | |
echo done | |
end_safe_function | |
echo declared | |
declare -f x-y_z | |
x-y_z | |
exit 42 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment