Skip to content

Instantly share code, notes, and snippets.

@searbe
Created May 17, 2012 11:58
Show Gist options
  • Save searbe/2718411 to your computer and use it in GitHub Desktop.
Save searbe/2718411 to your computer and use it in GitHub Desktop.
Automatically install public resources from Symfony2 bundles when a file changes
#!/bin/bash
# Useful when you're making lots of changes in bundle/Resources/public and want
# to see the changes quickly in your browser.
# chmod +x the file then call the command like `./watch_assets.sh`
# Make sure you're in the project root directory (the one containing app, src etc)
if [ -z `which inotifywait` ] ; then
echo "You must install inotify-tools to use watch_assets"
exit 1
fi
function update_assets {
php app/console assets:install web
chmod 777 app/cache -R
chown `logname`:www-data . -R
}
echo "Watching ./src/*/Resources/public... "
PUB_FILES=`find ./ -path ./src/*/Resources/public`
while inotifywait -re modify $PUB_FILES &>/dev/null ; do
sleep 1
echo -n "Change spotted! Installing assets... "
update_assets &>/dev/null
echo "done"
if [ ! -z `which notify-send` ] ; then
notify-send "Assets updated" "A change was detected & assets were updated"
fi
done
@searbe
Copy link
Author

searbe commented Jul 18, 2012

I've added the update_assets function so this gist actually like, works and stuff.

Note that in the update_assets function you should do whatever you want. At least make sure login-name:www-data are the user & group the assets need to belong to with your dev setup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment