Last active
August 29, 2015 14:16
-
-
Save gabesullice/1ebf89ef512920da7219 to your computer and use it in GitHub Desktop.
Find the Drupal root quickly in bash
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 | |
test_root () { | |
if [ "$(pwd)" != "/" ]; then | |
lnct=$(find . -maxdepth 2 -type f -path './includes/bootstrap.inc' | wc -l) | |
if [ $lnct -gt 0 ]; then | |
drupal_root=$(pwd) | |
return 0 | |
else | |
cd .. | |
test_root | |
return $? | |
fi | |
else | |
return 1 | |
fi | |
} | |
start_dir=$(pwd) | |
if test_root ; then | |
cd $start_dir | |
echo $drupal_root | |
exit 0 | |
else | |
cd $start_dir | |
echo "Not currently in a Drupal site directory." | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment