1 #From: Mark Kennedy <mark.t.kennedy@gmail.com> (<mtk@ny.ubs.com>)
2 #Message-ID: <35E2B899.63A02DF5@ny.ubs.com>
3 #Date: Tue, 25 Aug 1998 09:14:01 -0400
4 #To: chet@nike.ins.cwru.edu
5 #Subject: a newer version of the ksh-style 'autoload'
7 #enclosed you'll find 'autoload.v3', a version of the autoloader
8 #that emulates the ksh semantics of delaying the resolution (and loading) of the function
9 #until its first use. i took the liberty of simplifying the code a bit although it still uses the
10 #same functional breakdown. i recently went through the exercise of converting
11 #my ksh-based environment to bash (a very, very pleasant experience)
14 # the psuedo-ksh autoloader.
16 # The first cut of this was by Bill Trost, trost@reed.bitnet.
17 # The second cut came from Chet Ramey, chet@ins.CWRU.Edu
18 # The third cut came from Mark Kennedy, mtk@ny.ubs.com. 1998/08/25
28 local f=$(_autoload_resolve '$func')
37 _autoload_addlist $func
45 for func in ${_AUTOLOADS[@]}; do
46 [[ $func = "$1" ]] && return
49 _AUTOLOADS[${#_AUTOLOADS[@]}]=$1
56 for func in ${_AUTOLOADS[@]}; do
57 [[ $1 ]] && echo -n "autoload "
62 _autoload_remove_one()
65 local -a NEW_AUTOLOADS
67 for func in ${_AUTOLOADS[@]}; do
68 [[ $func != "$1" ]] && NEW_AUTOLOADS[${#NEW_AUTOLOADS[@]}]=$func
71 _AUTOLOADS=( ${NEW_AUTOLOADS[@]} )
79 for func in ${_AUTOLOADS[@]}; do
80 [[ $victim = "$func" ]] && unset -f $func && continue 2
82 echo "autoload: $func: not an autoloaded function" >&2
86 _autoload_remove_one $func
92 if [[ ! "$FPATH" ]]; then
93 echo "autoload: FPATH not set or null" >&2
99 for p in $( (IFS=':'; set -- ${FPATH}; echo "$@") ); do
101 if [ -f $p/$1 ]; then echo $p/$1; return; fi
104 echo "autoload: $1: function source file not found" >&2
109 if (( $# == 0 )) ; then _autoload_dump; return; fi
116 p) _autoload_dump printable; return;;
117 u) shift $((OPTIND-1)); _autoload_remove "$@"; return;;
118 *) echo "autoload: usage: autoload [-pu] [function ...]" >&2; return;;