Created
September 25, 2024 11:48
-
-
Save webflo/006a9b9df344af1014ce916b5ece2309 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -x | |
findDrush() { | |
local path="$1" | |
# Check if the vendor/bin/drush directory exists in the current directory | |
drushDir="$path/vendor/bin/drush" | |
if [ -e "$drushDir" ]; then | |
# Drush found, return the current directory | |
echo "$drushDir" | |
return | |
fi | |
# Move one level up the directory tree | |
parentDir=$(dirname "$path") | |
if [ "$parentDir" == "$path" ]; then | |
# If we reached the root directory, stop traversing | |
return | |
fi | |
# Check if the vendor/bin/drush directory exists in the parent directory | |
drushDir="$parentDir/vendor/bin/drush" | |
if [ -e "$drushDir" ]; then | |
# Drush found in the parent directory, return the parent directory | |
echo "$drushDir" | |
return | |
fi | |
# Recursively continue searching in the parent directory | |
findDrush "$parentDir" | |
} | |
while [[ $# -gt 0 ]]; do | |
case "$1" in | |
-r=*|--root=*) | |
drupalDir="${1#*=}" | |
shift 1 | |
;; | |
-r|--root) | |
drupalDir="$2" | |
shift 2 | |
;; | |
*) | |
args+=("$1") | |
shift | |
;; | |
esac | |
done | |
# If no dir provided, use the current directory | |
if [ -z "$drupalDir" ]; then | |
drupalDir=$(pwd) | |
fi | |
drush=$(findDrush "$drupalDir") | |
if [ -z "$drush" ]; then | |
echo "Drush not found in $drupalDir." | |
exit 1 | |
fi | |
drushCmd=("$drush" "${args[@]}") | |
# Pass the current environment variables to the drush command | |
export "${!BASH_ENV[@]}" >/dev/null | |
if [ "$DRUSH_ALLOW_XDEBUG" != 1 ] | |
then | |
export XDEBUG_MODE=off | |
fi | |
# Run the drush command | |
"${drushCmd[@]}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment