Parent directory

drush.complete.sh

1933 bytes
 1# BASH completion script for Drush.
 2#
 3# Place this in your /etc/bash_completion.d/ directory or source it from your
 4# ~/.bash_completion or ~/.bash_profile files.  Alternatively, source
 5# examples/example.bashrc instead, as it will automatically find and source
 6# this file.
 7#
 8# If you're using ZSH instead of BASH, add the following to your ~/.zshrc file
 9# and source it.
10#
11#   autoload bashcompinit
12#   bashcompinit
13#   source /path/to/your/drush.complete.sh
14
15# Ensure drush is available.
16which drush > /dev/null || alias drush &> /dev/null || return
17
18__drush_ps1() {
19  f="${TMPDIR:-/tmp/}/drush-env-${USER}/drush-drupal-site-$$"
20  if [ -f $f ]
21  then
22    __DRUPAL_SITE=$(cat "$f")
23  else
24    __DRUPAL_SITE="$DRUPAL_SITE"
25  fi
26
27  # Set DRUSH_PS1_SHOWCOLORHINTS to a non-empty value and define a
28  # __drush_ps1_colorize_alias() function for color hints in your Drush PS1
29  # prompt. See example.prompt.sh for an example implementation.
30  if [ -n "${__DRUPAL_SITE-}" ] && [ -n "${DRUSH_PS1_SHOWCOLORHINTS-}" ]; then
31    __drush_ps1_colorize_alias
32  fi
33
34  [[ -n "$__DRUPAL_SITE" ]] && printf "${1:- (%s)}" "$__DRUPAL_SITE"
35}
36
37# Completion function, uses the "drush complete" command to retrieve
38# completions for a specific command line COMP_WORDS.
39_drush_completion() {
40  # Set IFS to newline (locally), since we only use newline separators, and
41  # need to retain spaces (or not) after completions.
42  local IFS=$'\n'
43  # The '< /dev/null' is a work around for a bug in php libedit stdin handling.
44  # Note that libedit in place of libreadline in some distributions. See:
45  # https://bugs.launchpad.net/ubuntu/+source/php5/+bug/322214
46  COMPREPLY=( $(drush --early=includes/complete.inc "${COMP_WORDS[@]}" < /dev/null 2> /dev/null) )
47}
48
49# Register our completion function. We include common short aliases for Drush.
50complete -o bashdefault -o default -o nospace -F _drush_completion d dr drush drush5 drush6 drush7 drush8 drush.php