Zsh gh completion: Add completion for issues

This commit is contained in:
Adin Klotz 2020-08-20 21:44:03 -04:00
parent 768e4e835d
commit c3f0cabe84
1 changed files with 15 additions and 3 deletions

18
src/_gh
View File

@ -207,6 +207,9 @@ function _gh_help {
function _gh_issue { function _gh_issue {
local -a commands local -a commands
zstyle -s ':completion:*:*:gh:argument-1:' sort oldsort # Save the sort setting
zstyle ':completion:*:*:gh:argument-1:' sort false
_arguments -C \ _arguments -C \
'(-R --repo)'{-R,--repo}'[Select another repository using the `OWNER/REPO` format]:' \ '(-R --repo)'{-R,--repo}'[Select another repository using the `OWNER/REPO` format]:' \
'--help[Show help for command]' \ '--help[Show help for command]' \
@ -247,10 +250,17 @@ function _gh_issue {
_gh_issue_view _gh_issue_view
;; ;;
esac esac
zstyle ':completion:*:*:gh:argument-1:' sort $oldsort # Restore the sort setting
}
function __issue_numbers {
local options=$(gh issue list "$@" | awk -F '\t' '{print $1 "\\:" "\"" $3 " (" tolower($2) ")" "\""}' | tr '\n' ' ')
echo $options
} }
function _gh_issue_close { function _gh_issue_close {
_arguments \ _arguments -C \
"1:Issue:(($(__issue_numbers --state open)))" \
'--help[Show help for command]' \ '--help[Show help for command]' \
'(-R --repo)'{-R,--repo}'[Select another repository using the `OWNER/REPO` format]:' '(-R --repo)'{-R,--repo}'[Select another repository using the `OWNER/REPO` format]:'
} }
@ -283,7 +293,8 @@ function _gh_issue_list {
} }
function _gh_issue_reopen { function _gh_issue_reopen {
_arguments \ _arguments -C \
"1:Issue:(($(__issue_numbers --state closed)))" \
'--help[Show help for command]' \ '--help[Show help for command]' \
'(-R --repo)'{-R,--repo}'[Select another repository using the `OWNER/REPO` format]:' '(-R --repo)'{-R,--repo}'[Select another repository using the `OWNER/REPO` format]:'
} }
@ -295,7 +306,8 @@ function _gh_issue_status {
} }
function _gh_issue_view { function _gh_issue_view {
_arguments \ _arguments -C \
"1:Issue:(($(__issue_numbers --state all)))" \
'(-w --web)'{-w,--web}'[Open an issue in the browser]' \ '(-w --web)'{-w,--web}'[Open an issue in the browser]' \
'--help[Show help for command]' \ '--help[Show help for command]' \
'(-R --repo)'{-R,--repo}'[Select another repository using the `OWNER/REPO` format]:' '(-R --repo)'{-R,--repo}'[Select another repository using the `OWNER/REPO` format]:'