Last active
February 7, 2023 13:26
-
-
Save markwragg/857d8a1151ebf1f0afcdb3f6fb930c5a to your computer and use it in GitHub Desktop.
A PowerShell function to open the remote URL in the default browser for the git repo folder you are currently in at the command-line.
This file contains hidden or 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-GitUrl { | |
$RemoteURL = git config remote.origin.url | |
if ($RemoteURL) { | |
if ($RemoteURL -match '\.git$') { $RemoteURL = $RemoteURL -replace '\.git$','/' } | |
if ($IsMacOS) { | |
open $RemoteURL | |
} | |
else { | |
start $RemoteURL | |
} | |
} | |
else { | |
Write-Warning 'Could not retrieve remote.origin.url. Are you in a git folder?' | |
} | |
} | |
'ogu','ogh','github'| ForEach-Object { Set-Alias $_ Open-GitUrl } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you!