-
Install Dependencies
brew install jq brew install hub
-
Log into hub (from any repo just do
hub pr list
)- use your github username for username
- use a personal access token for password (token should have
repo
access)
-
Add script:
touch ~/whatever/path/openpr.sh chmod +x ~/whatever/path/openpr.sh
-
Add this code to
openpr.sh
#!/bin/zsh # Check if we're in a Git repository git rev-parse --is-inside-work-tree >/dev/null 2>&1 if [ $? -ne 0 ]; then echo "You are not inside a Git repository. Please navigate to a Git repository and try again." exit 1 fi # Get the current branch name current_branch=$(git symbolic-ref --short HEAD) if [ -z "$current_branch" ]; then echo "You are not on a valid Git branch. Please switch to a branch and try again." exit 1 fi # Get the GitHub user and repository name github_user_and_repo=$(git config --get remote.origin.url | sed 's|.*:\(.*\)/\(.*\)\.git|\1/\2|') # Get the pull request information pr_info=$(hub pr list -f "%I %H%n" | grep $current_branch) if [ -z "$pr_info" ]; then open "https://github.com/$github_user_and_repo/compare/$current_branch" else # Get the PR number pr_number=$(echo $pr_info | cut -d ' ' -f 1) # Open the pull request in the browser open "https://github.com/$github_user_and_repo/pull/$pr_number" fi
-
Add the alias to
.zshrc
:alais='~/whatever/path/openpr.sh`
-
Now from the root of any github repo that has a remote, you can just do:
openpr
Created
November 1, 2023 18:03
-
-
Save emmanuelnk/8fe9d2084b271bd27a9a704181dfd080 to your computer and use it in GitHub Desktop.
Open Github PR from Terminal (SSH Authorization)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment