Created
May 4, 2015 09:01
-
-
Save DanielBoerlage/8a0ded5d72e1a31b69ce to your computer and use it in GitHub Desktop.
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
DEP_DIR="/usr/local/lib" | |
# Usage: | |
# Bash function libraries start with the line | |
# depends lib-1 lib-2 | |
# And bash scripts start with the line | |
# source depends lib-1 lib-3 | |
function depends { | |
for dependency in "$@" | |
do | |
# this doesnt work on files with spaces | |
[[ "$sourced" == *" $dependency "* ]] && continue | |
[[ ! -f "${DEP_DIR}/$dependency" ]] && { | |
echo "missing dependency: $dependency" | |
exit | |
} | |
sourced+="$dependency " | |
source "${DEP_DIR}/$dependency" | |
done | |
} | |
sourced=" " | |
depends "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment