Line | |
---|
1 | # source.bash
|
---|
2 | # Author: Noah Friedman <friedman@prep.ai.mit.edu>
|
---|
3 | # Created: 1992-05-17
|
---|
4 | # Last modified: 1993-09-29
|
---|
5 | # Public domain
|
---|
6 |
|
---|
7 | # Commentary:
|
---|
8 | # Code:
|
---|
9 |
|
---|
10 | #:docstring source:
|
---|
11 | # Usage: source file ...
|
---|
12 | #
|
---|
13 | # Source forces file arguments to be considered in the current directory
|
---|
14 | # only, unless there is an absolute path starting with `/'. I think it's
|
---|
15 | # bad that the builtin "source" searches PATH, because PATH normally
|
---|
16 | # contains directories with binary files that aren't useful for bash to
|
---|
17 | # read and most people don't put "." first in their path.
|
---|
18 | #
|
---|
19 | # This "source" is capable of reading more than one file at a time. Return
|
---|
20 | # value is number of failed source attempts.
|
---|
21 | #:end docstring:
|
---|
22 |
|
---|
23 | # This function is not hygienic, but there's not much we can do about
|
---|
24 | # variable name conflicts here.
|
---|
25 |
|
---|
26 | ###;;;autoload
|
---|
27 | function source ()
|
---|
28 | {
|
---|
29 | local -i _source_failure_count=0
|
---|
30 | local _source_file
|
---|
31 |
|
---|
32 | for _source_file ; do
|
---|
33 | # Check first part of each filename. If it's not `/', `./', or
|
---|
34 | # `../' then prepend "./" to the path to force the builtin `source'
|
---|
35 | # not to go searching through PATH to find the file.
|
---|
36 | case "${_source_file}" in
|
---|
37 | /*|./*|../* ) ;;
|
---|
38 | * ) _source_file="./${_source_file}" ;;
|
---|
39 | esac
|
---|
40 |
|
---|
41 | builtin source "${_source_file}" ||
|
---|
42 | _source_failure_count="_source_failure_count + 1"
|
---|
43 |
|
---|
44 | done
|
---|
45 |
|
---|
46 | return ${_source_failure_count}
|
---|
47 | }
|
---|
48 |
|
---|
49 | #:docstring .:
|
---|
50 | # See "source"
|
---|
51 | #:end docstring:
|
---|
52 |
|
---|
53 | # So that `.' will call function definition of `source' instead of builtin
|
---|
54 |
|
---|
55 | ###;;;autoload
|
---|
56 | function . ()
|
---|
57 | {
|
---|
58 | source "$@"
|
---|
59 | }
|
---|
60 |
|
---|
61 | provide source
|
---|
62 |
|
---|
63 | # source.bash ends here
|
---|
Note:
See
TracBrowser
for help on using the repository browser.