- Create file:
sudo touch /usr/local/bin/drush
- Make file executable:
sudo chmod +x /usr/local/bin/drush
- Open the file, and copy and paste the script to it, save it.
Last active
October 10, 2024 08:40
-
-
Save jelmerdemaat/305bd1fc1faacb7d4ce5d4db88208f2c to your computer and use it in GitHub Desktop.
Custom drush command to find project specific drush binary inside vendor folder
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 -u | |
function drush() { | |
local root_dir='' | |
# Parse options | |
while getopts "r:" opt; do | |
case $opt in | |
r) | |
root_dir=$OPTARG | |
;; | |
\?) | |
echo "Invalid option: -$OPTARG" >&2 | |
return 1 | |
;; | |
esac | |
done | |
shift $((OPTIND - 1)) | |
# Start at the current directory or the specified root directory | |
if [[ -n "$root_dir" ]]; then | |
dir="$root_dir" | |
else | |
dir=$PWD | |
fi | |
# While not at the root (/) | |
while [[ "$dir" != "/" ]]; do | |
# If vendor/bin/drush exists, run it | |
if [[ -x "$dir/vendor/bin/drush" ]]; then | |
"$dir/vendor/bin/drush" "$@" | |
return | |
fi | |
# Go up one directory level | |
dir=$(dirname "$dir") | |
done | |
echo "Could not find drush in any parent directory." | |
return 1 | |
} | |
drush "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Source:
drush-ops/drush-launcher#105 (comment)