# ABOUT : BASH Shell auto completion for Drush - it auto-completes when you invoke drush with - 'd', 'dr', 'drush' or 'drush.php'. # WEB RESOURSES : See http://drupal.org/node/437568 - the issue that we use for this thing. # VERSION : 0.6 (entirely bash based, no php helper file or dedicated backend) # DATE : 090522 # INSTALL : (valid for debian with bash) make a symlink from /etc/bash_completion.d/drush -> /path/to/drush/drush.completion or source it from .bashrc or /etc/profile if you do not have privs for the symlinking # REQUIREMENTS : "drush" named symlink in your $PATH . It uses it to get some info by calling drush. # TODO : Limitations : # : 1. for now does not completes the 'dump' part of 'sql dump' - instead shows all commands - because of the whitespace between 'sql' and 'dump' # : 2. better modules/projects completion on dl/enable/disable ... for now we do a `find $drupal_root/modules/ $drupal_root/themes/ $drupal_root/sites/ -type f -name "*.info" -exec basename '{}' .info \; | tr '\n' ' '` ... # TODO : Roadmap : # : create an internal use --completion option for drush that will make completion suggestions # The func that bash uses for drush completion. _drush_completion() { local cur prev # init the array with the reply COMPREPLY=() # part of currently completed word cur=${COMP_WORDS[COMP_CWORD]} # prev completed word prev=${COMP_WORDS[COMP_CWORD-1]} drupal_root=`drush help --verbose | grep -A 1 "root directory at " | tail -1` # results to sth like "/var/www/vhosts/example.com" - no new line at its end # this is quite faster than `drush status --pipe` or `drush status --backend` drush_commands=`drush help --pipe | sed s/\"\ \"/\:/g | sed s/\"//g` # makes them :-delimited # output drush commands or .info files (projects and their modules) case $prev in @(enable|disable|uninstall|updatecode|update|info)) # these above are the module commands # @ means exactly one occurrence of any pattern. Deliberately no spaces or "" here # find all things with .info files below word_list=`find $drupal_root/modules/ $drupal_root/themes/ $drupal_root/sites/ -type f -name "*.info" -exec basename '{}' .info \; | tr '\n' ':'` ;; *) # list all drush commands word_list=$drush_commands ;; esac # generate completion suggestions based on already typed string oldIFS=$IFS # we need to hack IFS because completion of space-containing drush commands is not a nice task the least ;) IFS=: completions=`compgen -W '$word_list' -- $cur | tr "\n" ":"` #echo "<$completions>" # gives them one on per line COMPREPLY=( $completions ) IFS=$oldIFS } complete -F _drush_completion d dr drush drush.php