Zsh: Completion for PR numbers for gh commands

This commit is contained in:
Adin Klotz 2020-08-20 18:20:13 -04:00
parent b90c0a0a09
commit c477a23465
1 changed files with 21 additions and 8 deletions

29
src/_gh
View File

@ -367,14 +367,21 @@ function _gh_pr {
esac
}
function _pr_helper {
local options=$(gh pr list | awk -F '\t' '{print $1 "\\:" "\"" $2 " (" $3 ")" "\""}' | tr '\n' ' ')
echo $options
}
function _gh_pr_checkout {
_arguments \
_arguments -C \
"1:PR:(($(_pr_helper)))" \
'--help[Show help for command]' \
'(-R --repo)'{-R,--repo}'[Select another repository using the `OWNER/REPO` format]:'
}
function _gh_pr_close {
_arguments \
_arguments -C \
"1:PR:(($(_pr_helper)))" \
'--help[Show help for command]' \
'(-R --repo)'{-R,--repo}'[Select another repository using the `OWNER/REPO` format]:'
}
@ -397,7 +404,8 @@ function _gh_pr_create {
}
function _gh_pr_diff {
_arguments \
_arguments -C \
"1:PR:(($(_pr_helper)))" \
'(-c --color)'{-c,--color}'[Whether or not to output color: {always|never|auto}]:' \
'--help[Show help for command]' \
'(-R --repo)'{-R,--repo}'[Select another repository using the `OWNER/REPO` format]:'
@ -416,7 +424,8 @@ function _gh_pr_list {
}
function _gh_pr_merge {
_arguments \
_arguments -C \
"1:PR:(($(_pr_helper)))" \
'(-d --delete-branch)'{-d,--delete-branch}'[Delete the local and remote branch after merge]' \
'(-m --merge)'{-m,--merge}'[Merge the commits with the base branch]' \
'(-r --rebase)'{-r,--rebase}'[Rebase the commits onto the base branch]' \
@ -426,19 +435,22 @@ function _gh_pr_merge {
}
function _gh_pr_ready {
_arguments \
_arguments -C \
"1:PR:(($(_pr_helper)))" \
'--help[Show help for command]' \
'(-R --repo)'{-R,--repo}'[Select another repository using the `OWNER/REPO` format]:'
}
function _gh_pr_reopen {
_arguments \
_arguments -C \
"1:PR:(($(_pr_helper)))" \
'--help[Show help for command]' \
'(-R --repo)'{-R,--repo}'[Select another repository using the `OWNER/REPO` format]:'
}
function _gh_pr_review {
_arguments \
_arguments -C \
"1:PR:(($(_pr_helper)))" \
'(-a --approve)'{-a,--approve}'[Approve pull request]' \
'(-b --body)'{-b,--body}'[Specify the body of a review]:' \
'(-c --comment)'{-c,--comment}'[Comment on a pull request]' \
@ -454,7 +466,8 @@ function _gh_pr_status {
}
function _gh_pr_view {
_arguments \
_arguments -C \
"1:PR:(($(_pr_helper)))" \
'(-w --web)'{-w,--web}'[Open a pull request in the browser]' \
'--help[Show help for command]' \
'(-R --repo)'{-R,--repo}'[Select another repository using the `OWNER/REPO` format]:'