Skip to content

Instantly share code, notes, and snippets.

@natefaubion
Created June 7, 2012 02:52
Show Gist options
  • Save natefaubion/2886269 to your computer and use it in GitHub Desktop.
Save natefaubion/2886269 to your computer and use it in GitHub Desktop.
Sprockets-like require directives in a short shell script
#!/bin/bash
#usage: ./require.sh <root_dir> <main_file> [<output_file>]
cd $1
ftype=`echo $2 | awk -F . '{print $NF}'`
files=""
function parsedeps {
files="$1 $files"
deps=`egrep '^(#|//|/\*)= require .*$' $1 | awk "{print \\$3 \".$ftype\"}" | tail -r`
for dep in $deps; do parsedeps $dep; done
}
parsedeps $2
unique=`awk 'BEGIN{RS=ORS=" "}!a[$0]++' <<<$files`
if [ "$3" != "" ]
then cat $unique > $3
else cat $unique
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment