Revision 12828
Added by Aaron Marcuse-Kubitza almost 11 years ago
util.sh | ||
---|---|---|
315 | 315 |
fi # load new aliases |
316 | 316 |
if self_being_included; then |
317 | 317 |
|
318 |
rtrim() { log+ 3; sed 's/[[:space:]]+$//' <<<"$1"; } |
|
318 |
rtrim() { log_local; log+ 3; sed 's/[[:space:]]+$//' <<<"$1"; }
|
|
319 | 319 |
|
320 | 320 |
|
321 | 321 |
#### arrays |
... | ... | |
449 | 449 |
fi # load new aliases |
450 | 450 |
if self_being_included; then |
451 | 451 |
|
452 |
# usage: in func: log++; ... |
|
453 |
# outside func: log++; ...; log-- |
|
452 |
# usage: in func: log_local; log++; ...
|
|
453 |
# outside func: log_local; log++; ...; log--
|
|
454 | 454 |
# before cmd: clog++ cmd OR clog+ num cmd OR clog++ clog++... cmd |
455 | 455 |
# with a cmd, assignments are applied just to it, so log_local is not needed |
456 | 456 |
# without a cmd, assignments are applied to caller ("$@" expands to nothing) |
... | ... | |
467 | 467 |
log++() { log+ 1 "$@"; } |
468 | 468 |
log--() { log- 1 "$@"; } |
469 | 469 |
log!() { log- "$log_level" "$@"; } # force-displays next log message |
470 |
alias log+='log_local; "log+"' # don't expand next word because it's not a cmd
|
|
471 |
alias log++='log_local; "log++" ' # last space alias-expands next word
|
|
472 |
alias log--='log_local; "log--" ' # last space alias-expands next word
|
|
473 |
alias log!='log_local; "log!" ' # last space alias-expands next word
|
|
470 |
alias log+='"log+"' # don't expand next word because it's not a cmd |
|
471 |
alias log++='"log++" ' # last space alias-expands next word |
|
472 |
alias log--='"log--" ' # last space alias-expands next word |
|
473 |
alias log!='"log!" ' # last space alias-expands next word |
|
474 | 474 |
alias clog+='"log+"' # no last space because next word is not a cmd |
475 | 475 |
alias clog++='"log++" ' # last space alias-expands next word |
476 | 476 |
alias clog--='"log--" ' # last space alias-expands next word |
... | ... | |
539 | 539 |
die_e() # usage: cmd || [benign_error=1] die_e [|| handle error] |
540 | 540 |
{ |
541 | 541 |
save_e; kw_params benign_error |
542 |
if test "$benign_error"; then log++; fi |
|
542 |
if test "$benign_error"; then log_local; log++; fi
|
|
543 | 543 |
type="${benign_error:+info}" die "command exited with \ |
544 | 544 |
$(if test "$benign_error"; then echo status; else echo error; fi) $e" |
545 | 545 |
rethrow |
... | ... | |
692 | 692 |
|
693 | 693 |
echo_vars() # usage: echo_vars var... # only prints vars that are defined |
694 | 694 |
{ |
695 |
log+ 2 |
|
695 |
log_local; log+ 2
|
|
696 | 696 |
if can_log; then |
697 | 697 |
local var |
698 | 698 |
for var in "${@%%=*}"; do |
... | ... | |
735 | 735 |
# usage: "echo_func" "$FUNCNAME" "$@" && indent || true |
736 | 736 |
# exit status: whether function call was echoed |
737 | 737 |
{ |
738 |
log++; can_log || return |
|
738 |
log_local; log++; can_log || return
|
|
739 | 739 |
local func="$1"; shift |
740 | 740 |
local loc; loc="$(clog++ func_loc "$func")" || return |
741 | 741 |
echo_cmd "$loc" "$func" "$@" |
... | ... | |
863 | 863 |
|
864 | 864 |
setup_log_fd() # view logging output at verbosity >= 5 |
865 | 865 |
{ |
866 |
log+ 4; log-- echo_func |
|
866 |
log_local; log+ 4; log-- echo_func
|
|
867 | 867 |
fd_set_default '30>&2' || true # stdlog |
868 | 868 |
log_fd=30 # stdlog |
869 | 869 |
} |
... | ... | |
874 | 874 |
# this works even when /dev/tty isn't available |
875 | 875 |
# view logging output at verbosity >= 3 |
876 | 876 |
{ |
877 |
log+ 2; log-- echo_func |
|
877 |
log_local; log+ 2; log-- echo_func
|
|
878 | 878 |
# ignore errors if a source fd isn't open |
879 | 879 |
fd_set_default '20<&0' || true |
880 | 880 |
fd_set_default '21>&1' || true |
... | ... | |
925 | 925 |
PATH_rm() # usage: PATH_rm path... # removes components from the PATH |
926 | 926 |
{ |
927 | 927 |
echo_func; echo_vars PATH; : "${PATH?}" |
928 |
log_local |
|
928 | 929 |
log+ 2 |
929 | 930 |
split : "$PATH" |
930 | 931 |
local new_paths=() |
... | ... | |
975 | 976 |
|
976 | 977 |
cd() # indent is permanent within subshell cd was used in |
977 | 978 |
{ |
978 |
log++ echo_func |
|
979 |
log_local; log++ echo_func
|
|
979 | 980 |
cmd2rel_path; echo_cmd "$FUNCNAME" "$@" |
980 | 981 |
if can_log; then caller_indent; fi |
981 | 982 |
# -P: expand symlinks so $PWD matches the output of realpath |
Also available in: Unified diff
: local setting of log_level: use log_local instead of relying on the log aliases, so that these aliases can instead be used for wrapping commands (the more common use case)