This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# autoload bash scripts. Much faster than `source script.sh` | |
# usage: autoload script.sh | |
autoload() { | |
[ -f "$1" ] || { echo "Usage ${FUNCNAME[0]} <filename>"; return 1;} | |
filename="$1" | |
loadname="$(sed 's:\..*::' <<< $(basename $filename))" | |
if [ -z "$(eval echo \${${loadname}_loaded})" ]; then | |
functions=$(command grep -o "^[a-zA-Z0-9_:]* *()" $filename | sed 's/()//') | |
for f in $functions; do | |
eval " |