Project

General

Profile

« Previous | Next » 

Revision 8289

lib/util.run: Run run_cmd at shell exit (using trap) instead of requiring every runscript to have `run_cmd ` at the end of it

View differences:

util.run
17 17
	"$(dirname "${BASH_SOURCE[1]}")"/path_relative_to_caller
18 18
	"$top_dir"/path_relative_to_outermost_script
19 19
}
20

  
21
run_cmd "$@"
22 20
fi ####
23 21

  
24 22
echo_cmd () { echo "$PS4$*" >&2; }
......
36 34

  
37 35
run_cmd ()
38 36
{
39
	# only if called in outermost script (+1 for this script)
40
	if test "${#BASH_SOURCE[@]}" -eq 2; then
41
		test "$#" -ge 1 || usage "$0 cmd args" || return
42
		echo_cmd "$0" "$@"; "$@"
43
	fi
37
	set -- "${BASH_ARGV[@]}"
38
	test "$#" -ge 1 || usage "$0 cmd args" || return
39
	echo_cmd "$0" "$@"; "$@"
44 40
}
41
trap run_cmd EXIT
45 42

  
46 43
fwd () # usage: subdirs=(...); fwd "$FUNCNAME" "$@"
47 44
{
......
79 76
	)|echo_stdin|make --makefile=/dev/stdin \
80 77
self_dir="$(dirname "$(readlink -f "${BASH_SOURCE[1]}")")" "$@"
81 78
}
82

  
83
run_cmd "$@"

Also available in: Unified diff