forked from drush-ops/drush-launcher
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdrush
executable file
·68 lines (56 loc) · 1.5 KB
/
drush
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
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"
}
args=("$@")
while [[ $# -gt 0 ]]; do
case "$1" in
-r=*|--root=*)
drupalDir="${1#*=}"
shift 1
;;
-r|--root)
drupalDir="$2"
shift 2
;;
*)
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
# Run the drush command
"${drushCmd[@]}"