Thursday, July 17, 2014

Drush autocomplete in bash shell

For shell users like me, Drush autocomplete is a bliss. This blog will tell you how you can autocomplete Drush commands in bash shell. The commands provided here will work for Ubuntu systems, I am not sure whether they will work for other systems as I do not know where Drush is installed for other systems.

Install Drush in your system. If it is already installed, skip to step 2. Otherwise, you can install it from here

Drush already provides you with bash aliases and autocompletion scripts. We just need to place them in right place.

Execute sudo ln -s /usr/share/php/drush/drush.complete.sh /etc/bash_completion.d/ This shell script does the smart autocompletion, and here we link the source with existing bash settings. The script does the smart autcomplete job like, suggesting modules to be enabled/disabled.

All settings are done. Just restart the shell ("exit" the current shell and open a new shell) and you are good to go.

You can write "drush en" and then double press "tab" key for suggestions, you will see list of modules.

Update:
The location of drush.complete.sh may vary according to how you install drush. To find where the script resides, execute sudo find / -name "drush.complete.sh". Suppose the location is /home/subhojit/.composer/vendor/drush/drush/drush.complete.sh, you then execute the command sudo ln -s /home/subhojit/.composer/vendor/drush/drush/drush.complete.sh /etc/bash_completion.d/