Skip to content

Instantly share code, notes, and snippets.

@mpdude
Created November 11, 2014 11:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mpdude/13e90dca8171396ce12f to your computer and use it in GitHub Desktop.
Save mpdude/13e90dca8171396ce12f to your computer and use it in GitHub Desktop.
Initialize .idea/vcs.xml file with all Git or Mercurial repos below current directory
#!/usr/bin/env php
<?php
print <<<HEAD
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
HEAD;
$iter = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator(".", RecursiveDirectoryIterator::SKIP_DOTS),
RecursiveIteratorIterator::SELF_FIRST,
RecursiveIteratorIterator::CATCH_GET_CHILD // Ignore "Permission denied"
);
$paths = array($root);
foreach ($iter as $path => $dir) {
if ($dir->isDir() && preg_match('_^\.(/(?:.*))?/\.(git|hg)$_', $path, $matches)) {
print ' <mapping directory="$PROJECT_DIR$'.$matches[1].'" vcs="'.($matches[2] == 'hg' ? 'hg4idea' : 'Git').'" />' . "\n";
}
}
print <<<END
</component>
</project>
END;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment