Skip to content

Instantly share code, notes, and snippets.

@donatj
Created January 12, 2016 17:53
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 donatj/161acfa2bef46db99574 to your computer and use it in GitHub Desktop.
Save donatj/161acfa2bef46db99574 to your computer and use it in GitHub Desktop.
Open current project on Github. OS X only.
#!/usr/bin/env php
<?php
$cwd = getcwd();
$dirs = explode(DIRECTORY_SEPARATOR, $cwd);
$opened = [ ];
for( $i = count($dirs); $i >= 1; $i-- ) {
$set = array_slice($dirs, 0, $i);
$path = implode(DIRECTORY_SEPARATOR, $set);
$gitPath = $path . DIRECTORY_SEPARATOR . '.git';
if( is_dir($gitPath) ) {
$cfgPath = $gitPath . DIRECTORY_SEPARATOR . 'config';
if( is_readable($cfgPath) ) {
$ini = parse_ini_file($cfgPath, true);
foreach( $ini as $sect => $sectContent ) {
if( strpos($sect, "remote ") === 0 && !empty($sectContent['url']) ) {
if( preg_match('%(?:@|/)github\.com(?:/|:)(.*)/(.*)\.git%i', $sectContent['url'], $regs) ) {
if( empty($opened[$regs[1] . $regs[2]]) ) {
$opened[$regs[1] . $regs[2]] = true;
shell_exec('open ' . escapeshellarg("https://github.com/{$regs[1]}/{$regs[2]}"));
}
}
}
}
die(0);
}
}
}
fwrite(STDERR, "remote github repository not found\n");
die(1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment