Drush shell functions for easy module uninstalls

When working with Drupal in a local development environment, it is often necessary to disable and uninstall modules for various reasons. A module must be disabled before it can be uninstalled. I found it useful to have shell functions to issue the Drush pm-disable and pm-uninstall commands.

To set this up, add the following functions to the appropriate shell config files (ex: .bash_profile, .bashrc, .zshrc):

Bash:

drush-ui() { drush pm-disable -y $@ && drush pm-uninstall -y $@ ;}

Z shell:

drush-ui() { drush pm-disable -y $@ ; drush pm-uninstall -y $@ }

Make sure to source your shell configuration file or close and relaunch your terminal application for the functions to work properly.

Please note that the "-y" included in the above functions tells Drush to "assume 'yes' as answer to all prompts" (Reference: drush help). Also, drush pm-uninstall will process uninstall hooks for the module requested and this may result in data loss if variables are deleted and tables dropped. You have been warned!

Here is how to issue the command:

drush-ui module1 module2 module3

Enjoy!

Blog Category: