Rob Loach | 2c730cd | 2013-12-30 17:51:48 -0500 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | # |
| 3 | # bash completion support for Drush: |
| 4 | # https://github.com/drush-ops/drush |
| 5 | # |
| 6 | # Originally from: |
| 7 | # http://github.com/drush-ops/drush/blob/master/drush.complete.sh |
| 8 | |
| 9 | # Ensure drush is available. |
| 10 | which drush > /dev/null || alias drush &> /dev/null || return |
| 11 | |
| 12 | __drush_ps1() { |
| 13 | f="${TMPDIR:-/tmp/}/drush-env/drush-drupal-site-$$" |
| 14 | if [ -f $f ] |
| 15 | then |
| 16 | __DRUPAL_SITE=$(cat "$f") |
| 17 | else |
| 18 | __DRUPAL_SITE="$DRUPAL_SITE" |
| 19 | fi |
| 20 | |
| 21 | [[ -n "$__DRUPAL_SITE" ]] && printf "${1:- (%s)}" "$__DRUPAL_SITE" |
| 22 | } |
| 23 | |
| 24 | # Completion function, uses the "drush complete" command to retrieve |
| 25 | # completions for a specific command line COMP_WORDS. |
| 26 | _drush_completion() { |
| 27 | # Set IFS to newline (locally), since we only use newline separators, and |
| 28 | # need to retain spaces (or not) after completions. |
| 29 | local IFS=$'\n' |
| 30 | # The '< /dev/null' is a work around for a bug in php libedit stdin handling. |
| 31 | # Note that libedit in place of libreadline in some distributions. See: |
| 32 | # https://bugs.launchpad.net/ubuntu/+source/php5/+bug/322214 |
| 33 | COMPREPLY=( $(drush --early=includes/complete.inc "${COMP_WORDS[@]}" < /dev/null 2> /dev/null) ) |
| 34 | } |
| 35 | |
| 36 | # Register our completion function. We include common short aliases for Drush. |
| 37 | complete -o bashdefault -o default -o nospace -F _drush_completion d dr drush drush5 drush6 drush6 drush.php |