# Bash completion file for the Drupal Scripts Library. # See the README.txt file included with this distribution for more info on the project. # # Source this file to enable usful bash completion for the drupal script commands # Note, this is sourced from the bashrc_drupal.sh file. # The name of a script we can be sure is in the library EXAMPLE_SCRIPT="drupalLibrary.sh" # Define the location of the drupal scripts library if [[ -n "${DRUPAL_SCRIPT_DIR}" && ! -d "${DRUPAL_SCRIPT_DIR}" ]]; then unset DRUPAL_SCRIPT_DIR fi if [ -z "${DRUPAL_SCRIPT_DIR}" ]; then DRUPAL_SCRIPT_DIR="`dirname "\`which ${EXAMPLE_SCRIPT}\`"`" fi if [ -z "${DRUPAL_SCRIPT_DIR}" ]; then # Can't really go very far from here. unset DRUPAL_SCRIPT_DIR return fi # The _installs() function retunrs a list of available drupal installations. # Works by calling 'drupalReport.sh listsites' [ -n "${DRUPAL_SCRIPT_DIR}" ] && _installs() { cur=${COMP_WORDS[COMP_CWORD]} COMPREPLY=() # Allowable options are defined by the 'listsites' call to drupalReport.sh COMPREPLY=$( "${DRUPAL_SCRIPT_DIR}/drupalReport.sh" listsites ) COMPREPLY=( $( compgen -W '${COMPREPLY}' -- $cur ) ) } # The _modulesForInstall() function returns the modules installed for an drupal installation # $1 - installation name [ -n "${DRUPAL_SCRIPT_DIR}" ] && _modulesForInstall() { install="${1}" if [ -z "${install}" ]; then return 0 fi COMPREPLY="`bash -c ". \"${DRUPAL_SCRIPT_DIR}/drupalLibrary.sh\" ; getNonContribModuleList \"${install}\" ; getInstalledContribModuleList \"${install}\""`" COMPREPLY=( $( compgen -W '${COMPREPLY}' -- $cur ) ) } # The _drupalComplete() function provides the functionality that handles # completion functionality for specific drupal script library commands. # It will call installs() by default for any command/position combination # which is not specifically handled. [ -n "${DRUPAL_SCRIPT_DIR}" ] && _drupalComplete() { cmd=${COMP_WORDS[0]} cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} # The command position after flags are removed flaglessPos=${COMP_CWORD} for (( i=1 ; i <= ${COMP_CWORD} ; i++ )); do if [[ ${COMP_WORDS[i]} == -* ]]; then let flaglessPos=${flaglessPos}-1 else break fi done # $isFlag will be non-zero-length if starting a valid flag. # To be valid, has to be proceed by only flags and start with a "-" isFlag="" if [[ ${cur} == -* ]]; then isFlag="yes" for (( i=1 ; i < ${COMP_CWORD} ; i++ )); do if [[ ${COMP_WORDS[i]} != -* ]]; then isFlag="" break fi done fi case $cmd in dmd ) if [ $flaglessPos -eq 2 ]; then _modulesForInstall ${COMP_WORDS[1]} return 0 fi ;; drupalAlias.sh ) # handle flags if [ -n "${isFlag}" ]; then COMPREPLY=( $( compgen -W '-remove' -- $cur ) ) return 0 fi ;; drupalGitDeploy.sh ) # everything is positional if [ $flaglessPos -eq 1 ]; then COMPREPLY=( $( compgen -W 'install update remove' -- $cur ) ) return 0 elif [ $flaglessPos -eq 2 ]; then COMPREPLY=( $( compgen -W 'drupal module theme all allmodules' -- $cur ) ) return 0 elif [ $flaglessPos -eq 3 -a "module" == "${prev}" ]; then # maybe one day we'll come up w/ list of modules that can be installed, but not today. return 0 elif [ $flaglessPos -eq 3 -a "theme" == "${prev}" ]; then # maybe one day we'll come up w/ list of themes that can be installed, but not today. return 0 fi ;; drupalDBQuery.sh ) # handle flags if [ -n "${isFlag}" ]; then COMPREPLY=( $( compgen -W '-quiet' -- $cur ) ) return 0 fi # handle options if [ $flaglessPos -eq 1 ]; then COMPREPLY=( $( compgen -W 'clearcache clearsessions disablemodule enablemodule fileupload findalias findsitename fixcron fixfilename grepnodes listmodules modulestatus resetadmin setadmin setoffline setonline setpassword showcachetables showtables switchnodefiles users variable variableraw' -- $cur ) ) return 0 fi ;; drupalManageDrush.sh ) # handle options if [ $flaglessPos -eq 1 ]; then COMPREPLY=( $( compgen -W 'install update validate findmods' -- $cur ) ) return 0 fi ;; drupalManageLibraries.sh ) # handle options if [ $flaglessPos -eq 1 ]; then COMPREPLY=( $( compgen -W 'query install findmods' -- $cur ) ) return 0 fi # select from supported modules if [ $flaglessPos -eq 2 ]; then COMPREPLY=( $( compgen -W 'ckeditor fckeditor jquery_ui' -- $cur ) ) return 0 fi ;; drupalReport.sh ) # handle options if [ $flaglessPos -eq 1 ]; then COMPREPLY=( $( compgen -W 'listsites admin aliases dbconn dbparms dbvalid modules roles sitedir siteroot status statusnc themes updates users' -- $cur ) ) return 0 fi ;; drupalSetAccessCheck.sh ) # handle options if [ $flaglessPos -eq 1 ]; then COMPREPLY=( $( compgen -W 'true false' -- $cur ) ) return 0 fi ;; esac # If we're here, just return the list of sites. _installs } && complete -F _drupalComplete -o default $(for i in "$DRUPAL_SCRIPT_DIR"/*.sh; do echo ${i##*/}; done)