Code snippets for symfony 1.x

Navigation

Refine Tags

Snippets tagged "web"

Automatically create symlinks to plugins' web directories

I use this small bash script to automatically detect /plugins/*/web directories and symlink them in /web folder.

This is particularly useful for SVN installations of plugins, which do not handle this for you.

#!/bin/bash
 
if [ ! -d web -o ! -d plugins ]
then
  echo "You must be in a Symfony project root"
  exit 1
fi
 
# Create links from /web directory
cd web
 
# List plugins' web directories
ls -d "../plugins/*/web" | while read plugin_web
do
  plugin=$(basename $(dirname $plugin_web))
  if [ ! -d $plugin ]
  then
    ln -f -s -v $plugin_web $plugin
  fi
done
 
# Go back to project's root
cd ..
 

You could use a "compact" version as an alias ;)

alias ln_plugins_web="cd web && ls ../plugins/*/web | while read plugin_web; do plugin=$(basename $(dirname $plugin_web)); if [ ! -d $plugin ]; then ln -f -s -v $plugin_web $plugin; fi; done; cd .."
 

Note : if your bash installation does not provide "basename" and "dirname" commands, you can add them manually with those aliases

function dirname() {
  echo "$1" | sed 's/\/[^\/]*\(\/*\)\?$//';
}
 
function basename() {
  echo "$1" | sed 's/^.*\/\([^\/]\+\)\/*$/\1/
}
by Nicolas Chambrier on 2008-03-23, tagged bash  linux  plugins  web