Created
April 16, 2025 18:31
-
-
Save JeffreyJoumjian/95baab18931ce81070d0437d336519d8 to your computer and use it in GitHub Desktop.
Open a PR from current branch
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 gh-open { | |
action=compare | |
if [ "$1" = "-b" ]; then | |
action=tree | |
fi | |
# Get the current branch name | |
branch=$(git rev-parse --abbrev-ref HEAD) | |
# Get the remote repository URL | |
remote_url=$(git config --get remote.origin.url) | |
# Transform the remote URL to the GitHub URL | |
github_url=$(echo $remote_url | sed -e 's/[email protected]:/https:\/\/github.com\//' -e 's/\.git$//') | |
# Open the current branch on GitHub | |
if [[ "$OSTYPE" == "darwin"* ]]; then | |
open "${github_url}/${action}/${branch}" # macOS | |
else | |
xdg-open "${github_url}/${action}/${branch}" # Linux/WSL | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment