Skip to content

Instantly share code, notes, and snippets.

@caoyue
Last active October 21, 2021 12:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caoyue/c2e916f71e521180628bd26542edec2a to your computer and use it in GitHub Desktop.
Save caoyue/c2e916f71e521180628bd26542edec2a to your computer and use it in GitHub Desktop.
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