Project

General

Profile

« Previous | Next » 

Revision 9301

lib/sh/util.sh: log++/--: support running a command with the given log++/-- setting instead of applying it in the calling context. note that with no args, "$@" will expand to nothing and the var assignments will be applied in the calling context instead of to an executed command. this requires using $(()) syntax instead of let! to set the verbosity.

View differences:

lib/sh/util.sh
180 180

  
181 181
# usage: in func:      log++; ...         OR  log_local; "log++"; ...
182 182
#        outside func: log++; ...; log--
183
log++() { PS4="${PS4:0:1}$PS4";    let! verbosity--; }
184
log--() { PS4="${PS4#${PS4:0:1}}"; let! verbosity++; }
183
#        before cmd:   log++ cmd...
184
# with no args, "$@" expands to nothing and var assignments applied to caller
185
log++() { PS4="${PS4:0:1}$PS4"    verbosity=$((verbosity-1)) "$@"; }
186
log--() { PS4="${PS4#${PS4:0:1}}" verbosity=$((verbosity+1)) "$@"; }
185 187
alias log_local='declare PS4="$PS4" verbosity="$verbosity"'
186
alias log++='log_local; "log++"'
187
alias log--='log_local; "log--"'
188
alias log++='log_local; "log++" ' # last space alias-expands next word
189
alias log--='log_local; "log--" ' # last space alias-expands next word
188 190

  
189 191

  
190 192
# indent for call tree. this is *not* the log_level (below).

Also available in: Unified diff