Revision 9315
Added by Aaron Marcuse-Kubitza about 11 years ago
lib/sh/util.sh | ||
---|---|---|
359 | 359 |
|
360 | 360 |
## functions |
361 | 361 |
|
362 |
# usage: local func=...; set_func_loc; use $file, $line |
|
363 |
alias set_func_loc="$(cat <<'EOF' |
|
364 |
: "${func:?}" |
|
365 |
local func_info="$(shopt -s extdebug; declare -F "$func")" # 'func line file' |
|
366 |
func_info="${func_info#$func }" |
|
367 |
local line="${func_info%% *}" |
|
368 |
local file="${func_info#$line }" |
|
369 |
EOF |
|
370 |
)" |
|
371 |
|
|
372 |
fi # load new aliases |
|
373 |
if self_being_included; then |
|
374 |
|
|
375 |
func_loc() # gets where function declared in the format file:line |
|
376 |
{ local func="$1"; set_func_loc; echo "$(canon_rel_path "$file"):$line"; } |
|
377 |
|
|
362 | 378 |
# usage: func() { [minor=1] echo_func; ... } |
363 | 379 |
function echo_func() # usage: [minor=1] "echo_func" "$@" && indent || true |
364 | 380 |
# exit status: whether function call was echoed |
Also available in: Unified diff
lib/sh/util.sh: added func_loc(), which gets where a function was declared in the format file:line, and helper alias set_func_loc