Skip to content

Instantly share code, notes, and snippets.

@psmay
Last active August 29, 2015 14:10
Show Gist options
  • Save psmay/b90849fe7752006e897c to your computer and use it in GitHub Desktop.
Save psmay/b90849fe7752006e897c to your computer and use it in GitHub Desktop.
Get a list of scripts in a dir and allow them to order themselves using a "#require " line stating deps.
BASHRC_D=~/.bashrc.d
schedule()
{
(
while [ $# -gt 0 ]; do
local name="$1"
(
case "$name" in
*.sh | .* | __* )
# Skip
;;
*)
if [ -f "$name" -a -r "$name" ] ; then
sed '/^#require\s/!d; s/^#require\s//; s/\s\+/\n/g;' <"$name"
echo "$name"
fi
;;
esac
) | awk -v name="$name" '{ print name " " $0 }'
shift
done
) | tsort | tac
}
(cd "$BASHRC_D"; schedule *)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment