Project

General

Profile

« Previous | Next » 

Revision 9190

lib/sh/util.sh: limit_stderr(): moved before command echoing because it does not depend on it and is a separate feature

View differences:

lib/sh/util.sh
170 170
alias log++='{ PS4++; declare verbosity="$verbosity"; let! verbosity--; }'
171 171
alias log--='{ PS4--; declare verbosity="$verbosity"; let! verbosity++; }'
172 172

  
173
fi # load new aliases
174
if self_being_included; then
175

  
173 176
can_log() { test "$verbosity" -gt 0; } # verbosity=0 turns off all logging
174 177

  
175 178
log() { if can_log; then echo "$log_indent$PS4$1" >&2; fi; }
......
188 191
die() { save_e; "log_${type:-err}" "$1"; rethrow; }
189 192

  
190 193

  
194
### command verbose output
195

  
196
# usage: ([stdout2stderr=1] limit_stderr; cmd...) || return
197
# `|| return` needed on Mac because of bug where -e doesn't apply to ()
198
function limit_stderr()
199
{
200
	log++ # should only apply during this function for use by can_log
201
	if test "$stdout2stderr"; then
202
		local stderr_is_errors="${stderr_is_errors-1}"
203
		if ! can_log; then exec 1>/dev/null; else stdout2stderr; fi
204
	else
205
		if ! can_log; then exec 2>/dev/null; fi
206
	fi
207
}
208

  
209

  
191 210
### command echoing
192 211

  
193 212
alias echo_params='log "$*"'
......
264 283

  
265 284
### external command verbose output
266 285

  
267
# usage: ([stdout2stderr=1] limit_stderr; cmd...) || return
268
# `|| return` needed on Mac because of bug where -e doesn't apply to ()
269
function limit_stderr()
270
{
271
	log++ # should only apply during this function for use by can_log
272
	if test "$stdout2stderr"; then
273
		local stderr_is_errors="${stderr_is_errors-1}"
274
		if ! can_log; then exec 1>/dev/null; else stdout2stderr; fi
275
	else
276
		if ! can_log; then exec 2>/dev/null; fi
277
	fi
278
}
279

  
280 286
limit_stderr_cmd() # usage: [stdout2stderr=1] limit_stderr_cmd cmd...
281 287
{
282 288
	case "$1" in command) echo_run_prep; local cmd_echoed=1;; esac

Also available in: Unified diff