drup() and a cup of coffee

Keep calm and drush cc

Drush is certainly a tool that makes Drupal development faster. Even with that speed, I found myself typing the same commands over and over again every morning just to get started, and I wanted to cut down on that time. We use two repositories at Princeton, one for core and sites/all, and one for the sites/sitename folder. So, I had to update two repos (git pull), update the database just in case (drush updatedb), clear cache (drush cc all), and switch between directories to do so. And then if I had to switch over to another site that wasn't that day's focus, the process repeats itself, even for quick fixes.

Since I work in Ubuntu, I was able to leverage the .bashrc file in my home directory to add my own custom startup function. It relies heavily on the Typing less in Drush post from Nuvole. Below is the current version of the script.

cd /var/www/$1/sites/default/
cowsay "Changing directory to /var/www/"$1"/sites/default"
cowsay "Temporarily moving to root. Updating core."
(cdd && git pull && drush updatedb)
cowsay "Moving back to /var/www/"$1"/sites/default. Updating the "$1" repo."
git pull
cowsay "Clearing cache"
cowsay "Here is the state of your Features:"
cowsay -f eyes "Your site is ready go to. Let's go make some internet."

An example startup script to get your Drupal 7 site ready for development.

Notes on the code

.bashrc pros most likely won't be impressed with the above function, but the goal here is to encourage everyone who wants to learn to get started.

When I use this function, I call it like this: drup pace. "$1" in the function then gets replaced with "pace." The commands with the parenthesis means "complete these commands, then return to the current directory." For descriptions on the rest of the commands, check out the Nuvole post. It's also packed with autocomplete goodness.

And finally, why simply "echo" a comment to the user when you can cowsay (sudo apt-get install cowsay) it? ASCII cows are surprisingly good at brightening up a sleepy morning.


So why bring this up at all? Chances are you might be using one repo, or you might not have your sites located at /var/www/sitename, or you might be using multisite. Clearly my function above won't work for your case.

Then the point is to go, make it your own. Know that like everything else in Drupal, you can do things your own way, even if that way helps only you. That's power.

Plus, having a cow talk to you during morning coffee is a heck of a lot of fun.