| 1 | # source.bash
|
|---|
| 2 | # Author: Noah Friedman <[email protected]>
|
|---|
| 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 | /*|./*|../* ) ;;
|
|---|
|
|---|