Skip to content

Instantly share code, notes, and snippets.

@hammady
Created April 17, 2013 06:28
Show Gist options
  • Save hammady/5402193 to your computer and use it in GitHub Desktop.
Save hammady/5402193 to your computer and use it in GitHub Desktop.
BASH script to convert image urls in .CSS files to .ERB style asset paths. Example usage: ./erbify-css.sh src libfoo input-file.css converts: .showgrid { background: url(src/grid.png); } to: .showgrid { background: url(<%=asset_path("libfoo/grid.png")%>); }
#!/bin/bash
if [ $# -ne 3 ]; then
echo "Usage: $0 <substitute-path> <with-path> <css-file>"
exit 1
fi
from=$1
to=$2
file=$3
out=$file.erb
sed 's{url\s*(\s*'$from'\([^)]\+\){url(<%=asset_path("'$to'\1")%>{g' $file > $out
echo $out written
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment