Instantly share code, notes, and snippets.

@caoyue caoyue/gh.ps1
Last active Jun 22, 2017

Embed
What would you like to do?
open git host url for current repository with browser in powershell
function Open-GitWeb {
$r = git remote -v | Select-String -Pattern "(https:\/\/|git@)(?<git>.*)\.git"
if ($r.Matches.Length -gt 0) {
$t = "https://" + ($r.Matches[0].Groups |
Where-Object {$_.Name -eq "git"}).Value.Replace(":", "/")
Write-Host "gh: openning ",$t,"..." -ForegroundColor "green"
Start-Process $t
}
else
{
Write-Host "gh: not a git repository or origin not set correctly." -ForegroundColor "red"
}
}
Set-Alias gh Open-GitWeb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment