# Bash environment setup 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 # (Executing this file does not work -- must be sourced with '.' command.) # # This script must know how to find the Drupal Script Library when called. # The library directory must be in the PATH or # the environment variable DRUPAL_SCRIPT_DIR must be set. # If it the Drupal Script Library cannot be found, call is effectively a no-op. ### Envirnoment setup # The name of a script we can be sure is in the library EXAMPLE_SCRIPT="drupalLibrary.sh" # Find the script home dir. # If its already set, ensure it's pointing to a valid place. if [[ -n "${DRUPAL_SCRIPT_DIR}" && -d "${DRUPAL_SCRIPT_DIR}" && ! -f "${DRUPAL_SCRIPT_DIR}/${EXAMPLE_SCRIPT}" ]]; then unset DRUPAL_SCRIPT_DIR fi # If it's not set here, try finding in path if [ -z "${DRUPAL_SCRIPT_DIR}" ]; then export DRUPAL_SCRIPT_DIR="`dirname "\`which ${EXAMPLE_SCRIPT} 2>/dev/null \`"`" fi # If not set here, give up. if [ -z "${DRUPAL_SCRIPT_DIR}" ]; then # Can't really go very far from here. unset DRUPAL_SCRIPT_DIR return fi # Call the Drupal Scripts Library's 'bash_completion.sh' file if [ -f "${DRUPAL_SCRIPT_DIR}/bash_completion.sh" ]; then . "${DRUPAL_SCRIPT_DIR}/bash_completion.sh" fi ### Some utilities written as bash functions # changes to a drupal install site dir dcd() { cd "`drupalReport.sh sitedir "$1"`"; } # pushd to a drupal install site dir dpushd() { pushd "`drupalReport.sh sitedir "${1}"`"; } # mysql into a drupal site db dmysql() { mysql `drupalReport.sh dbconn "${1}"`; } # Change to a specific module and theme dmd () { cd "`drupalReport.sh sitedir "$1"`" && cd modules && if [ -n "${2}" -a -d "${2}" ]; then cd "${2}" elif [ -n "${2}" -a -d "contrib/${2}" ]; then cd "contrib/${2}" fi; } dtd () { cd "`drupalReport.sh sitedir "$1"`" && cd themes && if [ -n "${2}" -a -d "${2}" ]; then cd "${2}" elif [ -n "${2}" -a -d "contrib/${2}" ]; then cd "contrib/${2}" fi; } # make these autocomplete complete -F _drupalComplete -o default dcd dpushd dmysql dmd dtd dreadme() { for site in `drupalReport.sh listsites`; do cat "`drupalReport.sh sitedir ${site}`/backups/readme.backup.txt"; echo -e "\n================================="; done | less } ### Drush setup export DRUSH_ROOT="${DRUPAL_SCRIPT_DIR}/drush" # First make sure it's removed from the PATH (safe even if it doesn't exist) export PATH="`echo "${PATH}" | sed "s|:${DRUSH_ROOT}[^:]*||g"`" # Ensure dir exists and validate installation if [[ ! -d "${DRUSH_ROOT}" || ! -f "${DRUSH_ROOT}/drush.php" ]]; then unset DRUSH_ROOT fi if [ -n "${DRUSH_ROOT}" ]; then if [ -n "`drupalManageDrush.sh validate`" ]; then unset DRUSH_ROOT fi fi # If everything is kosher, provide drush functionality if [ -n "${DRUSH_ROOT}" ]; then # Runs drush w/in context of Drupal Script Library # Uses PHP_HOME variable if available # $1 site name # $* remaining drush parameters ddrush() { if [[ -n "${PHP_HOME}" && -d "${PHP_HOME}" && -x "${PHP_HOME}/bin/php" ]]; then phpExecutable="${PHP_HOME}/bin/php" elif [ -x "`which php 2>/dev/null`" ]; then phpExecutable="`which php 2>/dev/null`" else return fi site="${1}" if [[ -n "${site}" && -n "`drupalReport.sh listsites | grep ${site}`" ]]; then shift siteroot="`drupalReport.sh siteroot "${site}"`" "${phpExecutable}" "${DRUSH_ROOT}/drush.php" --php="${phpExecutable}" -r "${siteroot}" -l "http://${site}/" $* else "${phpExecutable}" "${DRUSH_ROOT}/drush.php" --php="${phpExecutable}" $* fi } complete -F _drupalComplete -o default ddrush fi