The difference between a “normal user” and a “power user” in computer speak is that power users learn to accomplish the same tasks normal users do on a computer, but in a much more efficient manner. For example, learning the short-cut keys on the keyboard for copy and paste (⌘C, ⌘V) can substantially improve your efficiency, as opposed to using your mouse to complete the same task. Essentially, the more you can free yourself from using the mouse on your computer, the quicker you become at completing the same tasks, making you much more efficient. How we can be much more efficient with Drupal? Are there ways we can use shortcuts to complete some of the mundane point and click tasks we do everyday with Drupal? The answer to both those questions is Drush, the DRUpal SHell.
Drush is a command line shell and Unix scripting interface for Drupal, a veritable Swiss Army knife designed to make life easier for those of us who spend some of our working hours hacking away at the command prompt.
--Drush Project Page
This article is part 1 of a three part series on Drush. In this article I will cover the basics of downloading Drupal, modules, themes, enabling/disabling modules, updating modules, and uninstalling modules. We will review the old way of doing things and then the Drush way of doing things. Future articles will include general up keep tasks for your Drupal site, and then writing custom commands for Drush.
Downloading Drupal
The typical way to download Drupal requires several steps:
- Go to drupal.org
- Find the download section on the right side of the screen
- Click the link for the version you want
- Download the Drupal compressed file
- Un-compress the file within the DocumentRoot of your web server.
- Finish the install process as normal
Downloading from CVS
Another way to accomplish this same task is to download Drupal from CVS. To do this you need to open up the terminal application on your computer. Mac users will need to install Xcode Tools, and Windows users will need to download cygwin and the cvs plugin to do this. Once you have the correct tools installed, to download from CVS you type in the following command:
<?php
# This should be all typed on one line
cvs -z6 -d:pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal
-r DRUPAL-6-12 drupal-6.12
?>
This command would effectively download Drupal 6.12 to a directory drupal-6.12 in your current path. For more details about this command, look at http://drupal.org/node/320. This command just eliminated 5 steps to the install process. The command is quite long to memorize if you’re not using it all the time. This is where Drush comes in. To download Drupal with Drush, just type:
<?php
drush dl drupal
?>
This will download the latest version of Drupal to a directory called drupal in your current path. Drush is smart and finds the latest version for you, you don’t need to know the version number. By default drush will download the packaged up version of drupal, and unpack it for you in your working directory. Being a developer, I like having the CVS version of Drupal, having code that isn’t in version control just doesn't cut it for me. Fortunately drush has a config file you can modify to download from CVS.
drushrc.php
In the download directory for drush there is a file named example.drushrc.php. Copy this file to drushrc.php in the same directory and then open it up to modify. You use this file to add default options to drush, so you don’t have to type them at the command line. The only option I modify in this file is uncommenting the line that specifies the package-handler
<?php
$options['package-handler'] = 'cvs';
?>
Now everything I download using drush will come from CVS.
Downloading Modules and Themes
Downloading modules and themes is simple too. You no longer need to navigate to the project page to find the latest versions of the project you want. You just tell Drush to go download them for you. You can even pass multiple projects to the drush dl command, and it will download them all:
drush dl zen views cck ninesixty
Drush can distinguish between themes and modules so it will put the downloads in their appropriate directory as shown above.
Enabling Modules
Rather than navigating to the Modules page to install your modules, which is time consuming, enable them using drush, (Before you can do this step, you need to have fully installed Drupal using the Installer)
<?php
drush enable views views_ui content text number
?>
That command will enable the views modules, and CCK with a couple field types.
Disabling Modules
If you need to disable a module you can just type:
<?php
drush disable views
?>
What makes the drush disable command really nice is it allows you to disable modules that have dependent modules enabled. If you are familiar with disabling modules from the Modules page of your drupal install, you know that you need to disable all the dependencies of a module before you can actually disable the depended on module. This requires submitting the Modules page several times before you disable a module like Views.
Drush will find all the dependencies of the module you want to disable and tell you that there are dependencies. It will then disable all the dependent modules upon confirmation. THIS IS A HUGE TIME SAVER!
Uninstalling Modules
Disabling modules does not uninstall them from Drupal. When you disable a module there is still meta data left in the system table of drupal, as well as any variables that may have been saved in the variables table, and any custom database tables in the database, if the module created tables. Drush allows you to uninstall modules as if they were never installed (given that the module implements hook_uninstall correctly.)
To uninstall a module just type:
drush uninstall views content
This will run the uninstaller for both views and CCK
Conclusion
As you can see, Drush can save you mounds of time by leveraging the command line and freeing yourself from the mouse. I have only scratched the surface of the things you can do with Drush. By using Drush we have sidestepped the web browser and downloaded drupal, downloaded modules and themes, enabled and disabled modules, and uninstalled modules. All of these tasks are typically done in a web browser and require the use of a mouse navigating from page to page. We have circumvented all of that by using Drush and made ourselves much more efficient.
In our next article we look at general up keep tasks you can do with drush, after you have everything downloaded and installed.