Auto select Drush version for Drupal 7/8 core

Public

Drush 6 supports Drupal 8 core. This bash/zsh function allows to use one "drush" command for two Drush versions.
You have to check variables "drush5" (stable Drush 5 for common tasks) and "drush6" (latest Drush 6-dev for Drupal 8) and set them according to your environment.

Get raw version
bash
  1. # Function selects Drush 6 if we are in Drupal 8 folder.
  2. drush() {
  3. drush5=/usr/local/bin/drush # Set your path to Drush 5
  4. drush6="`which drush6`" # Set your path to Drush 6
  5.  
  6. dir="`pwd`"
  7.  
  8. until [ $dir = "/" ]
  9. do
  10. # Try to find Drupal 7.
  11. if [ -f "$dir/includes/database/database.inc" ]; then
  12. command $drush5 "$@"
  13. return
  14. fi
  15.  
  16. # Try to find Drupal 8.
  17. if [ -f "$dir/core/lib/Drupal.php" ]; then
  18. command $drush6 "$@"
  19. return
  20. fi
  21.  
  22. # Go to parrent directory.
  23. dir="`dirname $dir`"
  24. done
  25.  
  26. # Nothing found about Drupal version. Fallback to Drush 5.
  27. command $drush5 "$@"
  28. }

Comments

msankhala's picture

drush 6 doesn't support drupal8. Today i cloned the drupal 8 with command
git clone --branch 8.x <a href="http://git.drupal.org/project/drupal.git">http://git.drupal.org/project/drupal.git</a>
and updated my drush with  'pear update drush/drush'
my drupal 8 code and drush is updated when i try to install some module with drush then it give me error.
Drush 6.0 does not support Drupal 8. See http://drupal.org/project/drush for more information.

msankhala's picture

I cloned drupal and drush from github now its working fine.

nitish's picture

hey,
This is quite helpful I actually screwed my drush by updating it for drupal8.