Skip to content

Instantly share code, notes, and snippets.

@DanielBoerlage
Created May 4, 2015 09:01
Show Gist options
  • Save DanielBoerlage/8a0ded5d72e1a31b69ce to your computer and use it in GitHub Desktop.
Save DanielBoerlage/8a0ded5d72e1a31b69ce to your computer and use it in GitHub Desktop.
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