Revision 9174
Added by Aaron Marcuse-Kubitza over 11 years ago
lib/sh/util.sh | ||
---|---|---|
182 | 182 |
alias PS4++='declare PS4="${PS4:0:1}$PS4"' |
183 | 183 |
alias PS4--='declare PS4="${PS4#${PS4:0:1}}"' |
184 | 184 |
|
185 |
# usage: in func: inc_log_level; ...
|
|
186 |
# outside func: inc_log_level; ...; dec_log_level
|
|
187 |
alias inc_log_level='{ PS4++; declare verbosity="$verbosity";let! verbosity--;}'
|
|
188 |
alias dec_log_level='{ PS4--; declare verbosity="$verbosity";let! verbosity++;}'
|
|
185 |
# usage: in func: log++; ...
|
|
186 |
# outside func: log++; ...; log--
|
|
187 |
alias log++='{ PS4++; declare verbosity="$verbosity";let! verbosity--;}'
|
|
188 |
alias log--='{ PS4--; declare verbosity="$verbosity";let! verbosity++;}'
|
|
189 | 189 |
|
190 | 190 |
|
191 | 191 |
### command echoing |
... | ... | |
210 | 210 |
|
211 | 211 |
.() |
212 | 212 |
{ |
213 |
cmd2rel_path; set -- . "$@"; (inc_log_level; echo_params); indent
|
|
213 |
cmd2rel_path; set -- . "$@"; (log++; echo_params); indent
|
|
214 | 214 |
builtin "$@" |
215 | 215 |
} |
216 | 216 |
|
... | ... | |
235 | 235 |
|
236 | 236 |
function echo_func() |
237 | 237 |
{ |
238 |
inc_log_level
|
|
238 |
log++
|
|
239 | 239 |
local script="$(canon_rel_path "${BASH_SOURCE[1]}")" |
240 | 240 |
echo_cmd "$script:${BASH_LINENO[0]}" "${FUNCNAME[1]}" "$@" |
241 | 241 |
} |
242 | 242 |
alias echo_func='echo_func "$@"' |
243 |
alias echo_minor_func='(inc_log_level; echo_func)'
|
|
243 |
alias echo_minor_func='(log++; echo_func)'
|
|
244 | 244 |
|
245 | 245 |
## vars |
246 | 246 |
|
247 | 247 |
echo_vars() # usage: echo_vars var... |
248 | 248 |
{ |
249 |
inc_log_level; inc_log_level
|
|
249 |
log++; log++
|
|
250 | 250 |
if can_log; then |
251 | 251 |
local var |
252 | 252 |
for var in "${@%%=*}"; do log "$(declare -p "$var")"; done |
... | ... | |
266 | 266 |
# `|| return` needed on Mac because of bug where -e doesn't apply to () |
267 | 267 |
function limit_stderr() |
268 | 268 |
{ |
269 |
inc_log_level # should only apply during this function for use by can_log
|
|
269 |
log++ # should only apply during this function for use by can_log
|
|
270 | 270 |
if test "$stdout2stderr"; then |
271 | 271 |
local stderr_is_errors="${stderr_is_errors-1}" |
272 | 272 |
if ! can_log; then exec 1>/dev/null; else stdout2stderr; fi |
... | ... | |
295 | 295 |
|
296 | 296 |
echo_stdin() # usage: input|echo_stdin|cmd |
297 | 297 |
{ |
298 |
inc_log_level
|
|
298 |
log++
|
|
299 | 299 |
if can_log; then |
300 | 300 |
pipe_delay |
301 | 301 |
echo ----- >&2 |
... | ... | |
320 | 320 |
|
321 | 321 |
set_fd() # usage: dest=fd dir='[<>]' src=fd [noclobber=1] set_fd |
322 | 322 |
{ |
323 |
inc_log_level; echo_func
|
|
323 |
log++; echo_func
|
|
324 | 324 |
: "${dest:?}" "${dir:?}" "${src:?}" |
325 | 325 |
test ! "$noclobber" || require_fd_not_exists "$dest" || return 0 |
326 | 326 |
echo_eval exec "$dest$dir&$src" |
... | ... | |
339 | 339 |
# allows commands to access global stdin/stdout/stderr using fd 20/21/22 |
340 | 340 |
# this works even when /dev/tty isn't available |
341 | 341 |
{ |
342 |
inc_log_level; echo_func
|
|
342 |
log++; echo_func
|
|
343 | 343 |
local prefix=2 |
344 | 344 |
# ignore errors if a source fd isn't open |
345 | 345 |
src=0 dir='<' shadow_fd || true |
Also available in: Unified diff
lib/sh/util.sh: renamed inc_log_level/dec_log_level to shorter log++/log--