Created
June 7, 2012 02:52
-
-
Save natefaubion/2886269 to your computer and use it in GitHub Desktop.
Sprockets-like require directives in a short shell script
This file contains 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
#!/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