Created
January 12, 2016 17:53
-
-
Save donatj/161acfa2bef46db99574 to your computer and use it in GitHub Desktop.
Open current project on Github. OS X only.
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
#!/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