Skip to content

Instantly share code, notes, and snippets.

@gabesullice
Last active August 29, 2015 14:16
Show Gist options
  • Save gabesullice/1ebf89ef512920da7219 to your computer and use it in GitHub Desktop.
Save gabesullice/1ebf89ef512920da7219 to your computer and use it in GitHub Desktop.
Find the Drupal root quickly in bash
#!/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