Last active
October 21, 2021 12:26
-
-
Save caoyue/c2e916f71e521180628bd26542edec2a to your computer and use it in GitHub Desktop.
open git host url for current repository with browser in powershell
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
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