Revision 12832
Added by Aaron Marcuse-Kubitza almost 11 years ago
trunk/lib/sh/util.sh | ||
---|---|---|
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) |
457 | 457 |
# "${@:2}" expands to all of $@ after *1st* arg, not 2nd ($@ indexes start at 1) |
458 |
log+()
|
|
458 |
log:() # sets explicit log_level
|
|
459 | 459 |
{ |
460 | 460 |
if test $# -gt 1; then log_local; fi # if cmd, only apply assignments to it |
461 | 461 |
# no local vars because w/o cmd, assignments should be applied to caller |
462 |
log_level=$((log_level+$1))
|
|
462 |
log_level="$1"
|
|
463 | 463 |
PS4="$(str="${PS4:0:1}" n=$((log_level-1)) repeat)${PS4: -2}" |
464 | 464 |
"${@:2}" |
465 | 465 |
} |
466 |
log+() { log: $((log_level+$1)) "${@:2}"; } |
|
466 | 467 |
log-() { log+ "-$1" "${@:2}"; } |
467 | 468 |
log++() { log+ 1 "$@"; } |
468 | 469 |
log--() { log- 1 "$@"; } |
469 | 470 |
log!() { log- "$log_level" "$@"; } # force-displays next log message |
470 |
# no log+/- alias needed because next word is not an alias-expandable cmd |
|
471 |
# no log:/+/- alias needed because next word is not an alias-expandable cmd
|
|
471 | 472 |
alias log++='"log++" ' # last space alias-expands next word |
472 | 473 |
alias log--='"log--" ' # last space alias-expands next word |
473 | 474 |
alias log!='"log!" ' # last space alias-expands next word |
Also available in: Unified diff
lib/sh/util.sh: added log:(), which sets an explicit log_level. this also simplifies log+().