Skip to content

Instantly share code, notes, and snippets.

@acouch
Last active August 29, 2015 14:04
Show Gist options
  • Save acouch/d9f3437eecd4ed472d38 to your computer and use it in GitHub Desktop.
Save acouch/d9f3437eecd4ed472d38 to your computer and use it in GitHub Desktop.
drush alias lookup
<?php
function findFiles($base_dir, $asset_dir, $extensions = array()) {
function glob_recursive($base_dir, &$directories = array()) {
foreach(glob($base_dir, GLOB_ONLYDIR | GLOB_NOSORT) as $folder) {
$directories[] = $folder;
glob_recursive("{$folder}/*", $directories);
}
}
glob_recursive($base_dir, $directories);
$files = array();
foreach ($directories as $base_dir) {
if (strpos($base_dir, $asset_dir) != FALSE) {
foreach ($extensions as $extension) {
foreach (glob("{$base_dir}/*.{$extension}") as $file) {
$files[$base_dir] = $base_dir;
}
}
}
}
return $files;
}
$paths = drush_get_context('ALIAS_PATH');
$file_cache = dirname(__FILE__) . '/drush_alias_paths.txt';
if (!file_exists($file_cache)) {
$cached_paths = findFiles("/var/www", 'drush', array("drushrc.php"));
file_put_contents($file_cache, implode(PHP_EOL, $cached_paths), FILE_APPEND);
$paths = array_merge((array) $paths, (array) $cached_paths);
}
else {
$cached_paths = explode("\n", file_get_contents(dirname(__FILE__) . '/drush_alias_paths.txt'));
$paths = array_merge((array) $paths, (array) $cached_paths);
}
drush_set_context('ALIAS_PATH', $paths);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment