Skip to content

Instantly share code, notes, and snippets.

@JeffreyJoumjian
Created April 16, 2025 18:31
Show Gist options
  • Save JeffreyJoumjian/95baab18931ce81070d0437d336519d8 to your computer and use it in GitHub Desktop.
Save JeffreyJoumjian/95baab18931ce81070d0437d336519d8 to your computer and use it in GitHub Desktop.
Open a PR from current branch
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