Using bash "alias" with Drush to save on typing

Drush is great. In fact, I can’t remember a time where I didn’t use drush as a daily tool for managing and developing on Drupal. It saves so much time and effort from clicking through configuration windows in a browser and instead allows you to type out what you want directly.

But can we do better? Can we save even more time? We sure can!

If you’re using bash in your terminal (which you most likely are) you can setup “alias” commands to shorten often used typed out commands.

For example, I use drush to toggle devel_themer on and off all day long. I type in

drush en devel_themer -y
drush dis devel_themer -y

The -y skips the confirmation option to enable/disable modules

But with the amount of times a day I write that, it would be great if I could shrink that down even more. Now I could create a new drush command or module which implements a drush command to do this, but that seems a little overkill. Instead I added an alias of “themeron” and “themeroff” to my bash profile.

Here’s how you do it.

  1. Launch your terminal session and edit your .bash_profile file (ex: nano ~/.bash_profile)
  2. At the end of the file add the following
alias themeroff="drush dis -y devel_themer"
alias themeron="drush en -y devel_themer"
  1. Reload or logout/login to your terminal session

And you’re done. You can now trigger the enabling and disabling of drush using the alias “themeron” and “themeroff”. This is just the beginning. If you use “drush cc all” quite a bit, why not create an alias like “dcc” and save the extra keystrokes.

You do however have to check to see if your alias is already used as a command. You can try just typing in the alias you’re hoping to use (and hope that nothing bad will happen if the command does in fact exist) or better yet use the command “which” to find out if it’s been registered

which cc
which dcc
/usr/bin/which: no dcc in (/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/home/mwinstone/bin)

In this example, “cc” is taken. But “dcc” isn’t.

So enjoy your aliases and save on some typing.