Last active
August 10, 2025 13:49
-
-
Save iUsmanN/d46f9e420065831fcbe4e568d45d4bb0 to your computer and use it in GitHub Desktop.
Terminal PRs
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
| _get_collaborator_match() { | |
| local query="$1" | |
| local repo | |
| repo=$(gh repo view --json nameWithOwner --jq .nameWithOwner) || return 1 | |
| local login_match | |
| login_match=$(gh api "repos/$repo/collaborators" --paginate --jq '.[].login' \ | |
| | grep -i "^$query" | head -n 1) | |
| if [[ -n "$login_match" ]]; then | |
| echo "$login_match" | |
| return 0 | |
| fi | |
| while IFS= read -r login; do | |
| local name | |
| name=$(gh api "users/$login" --jq '.name // ""') || true | |
| if [[ -n "$name" ]]; then | |
| # Case-insensitive prefix match on real name | |
| if echo "$name" | grep -iq "^$query"; then | |
| echo "$login" | |
| return 0 | |
| fi | |
| # Case-insensitive substring match | |
| if echo "$name" | grep -iq "$query"; then | |
| echo "$login" | |
| return 0 | |
| fi | |
| fi | |
| done < <(gh api "repos/$repo/collaborators" --paginate --jq '.[].login') | |
| return 1 | |
| } | |
| gpr() { | |
| if [[ "${1:-}" == "ls" ]]; then | |
| gh pr list --json number,title,labels,assignees,createdAt,isDraft \ | |
| --template '{{ $grey := "\033[90m" }}{{ $yellow := "\033[1;33m" }}{{ $reset := "\033[0m" }}{{ printf "%s%-6s %-40s %-38s %-25s %-12s %-6s%s\n" $yellow "NUMBER" "TITLE" "LABELS" "ASSIGNEES" "CREATED_AT" "DRAFT" $reset }}{{ range . }}{{ $labels_raw := "" }}{{ range $i, $l := .labels }}{{ if gt $i 0 }}{{ $labels_raw = printf "%s, %s" $labels_raw $l.name }}{{ else }}{{ $labels_raw = $l.name }}{{ end }}{{ end }}{{ $labels_cell := printf "%-38.38s" $labels_raw }}{{ $labels_colored := printf "%s%s%s" $grey $labels_cell $reset }}{{ $ass := "" }}{{ range $i, $a := .assignees }}{{ if gt $i 0 }}{{ $ass = printf "%s, %s" $ass $a.login }}{{ else }}{{ $ass = $a.login }}{{ end }}{{ end }}{{ printf "%-6.0f %-40.40s %s %-25.25s %-12s %-6t\n" .number .title $labels_colored $ass (slice .createdAt 0 10) .isDraft }}{{ end }}' | |
| elif [[ "${1:-}" == "a" && -n "${2:-}" ]]; then | |
| local pr_number="$2" | |
| shift 2 | |
| local query="$*" | |
| local person | |
| if [[ -n "$query" ]]; then | |
| person=$(_get_collaborator_match "$query") | |
| if [[ -z "$person" ]]; then | |
| echo "No collaborator found matching: $query" | |
| return 1 | |
| fi | |
| else | |
| person=$(gh api user --jq .login) | |
| fi | |
| gh pr edit "$pr_number" --add-assignee "$person" && echo | |
| gpr ls | |
| else | |
| echo "Usage:" | |
| echo " gpr ls # list PRs" | |
| echo " gpr a <pr-number> [name|username...] # assign by name or username (partial ok) or yourself" | |
| return 1 | |
| fi | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
1 - Put the gu-pr.sh file in the ~ dir
2 - Open/Create .zshrc file in ~ dir (only on Mac) and add the line
source ~/gu-pr.shfollowed by an empty line.3 - Restart terminal and use
gpr lsto see PRs in repo.