Revision 9168
Added by Aaron Marcuse-Kubitza over 11 years ago
util.sh | ||
---|---|---|
8 | 8 |
|
9 | 9 |
realpath() { readlink -f -- "$1"; } |
10 | 10 |
|
11 |
include_guard_var() { realpath "$1"|"command" sed 's/[^a-zA-Z0-9_]/_/g'; }
|
|
11 |
include_guard_var() { realpath "$1"|builtin command sed 's/[^a-zA-Z0-9_]/_/g'; }
|
|
12 | 12 |
|
13 | 13 |
self_not_included() # usage: if self_not_included; then ... fi |
14 | 14 |
{ |
... | ... | |
223 | 223 |
function command() # usage: [stderr_is_errors=1] command extern_cmd... |
224 | 224 |
# to view only explicitly-displayed errors: explicit_errors_only=1 script... |
225 | 225 |
{ |
226 |
test "$cmd_echoed" || echo_run_prep |
|
226 | 227 |
set -- -- "$@" # prepend -- so command name not treated as `command` option |
227 | 228 |
set -- builtin command "$@" |
228 | 229 |
if test "$stderr_is_errors"; then "$@" 2>&22 # ensure errors are visible |
229 | 230 |
else "$@"; fi |
230 | 231 |
} |
231 | 232 |
|
232 |
# echo all external commands |
|
233 |
alias command='echo_run command' |
|
234 |
|
|
235 | 233 |
# auto-echo common external commands |
236 | 234 |
for cmd in env rm; do alias "$cmd=command $cmd"; done; unset cmd |
237 | 235 |
|
... | ... | |
281 | 279 |
|
282 | 280 |
limit_stderr_cmd() # usage: [stdout2stderr=1] limit_stderr_cmd cmd... |
283 | 281 |
{ |
284 |
case "$1" in echo_run) shift; echo_run_prep;; esac
|
|
282 |
case "$1" in command) echo_run_prep; local cmd_echoed=1;; esac
|
|
285 | 283 |
(limit_stderr; "$@") || return |
286 | 284 |
} |
287 | 285 |
alias limit_stderr_cmd='limit_stderr_cmd ' # last space alias-expands next word |
Also available in: Unified diff
lib/sh/util.sh: command(): perform echo_run_prep itself instead of requiring echo_run to be added in an alias. echo_run_prep will not be performed if limit_stderr_cmd() has performed it already outside the limit_stderr section. this requires using `builtin command` instead of "command" when you don't want the echoing (such as in include_guard_var()).