From c3f0cabe8453585b4e0b4b2a8e61ef7b09e77f0f Mon Sep 17 00:00:00 2001 From: Adin Klotz Date: Thu, 20 Aug 2020 21:44:03 -0400 Subject: [PATCH] Zsh gh completion: Add completion for issues --- src/_gh | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/_gh b/src/_gh index f748226..c27548b 100644 --- a/src/_gh +++ b/src/_gh @@ -207,6 +207,9 @@ function _gh_help { function _gh_issue { local -a commands + zstyle -s ':completion:*:*:gh:argument-1:' sort oldsort # Save the sort setting + zstyle ':completion:*:*:gh:argument-1:' sort false + _arguments -C \ '(-R --repo)'{-R,--repo}'[Select another repository using the `OWNER/REPO` format]:' \ '--help[Show help for command]' \ @@ -247,10 +250,17 @@ function _gh_issue { _gh_issue_view ;; 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 { - _arguments \ + _arguments -C \ + "1:Issue:(($(__issue_numbers --state open)))" \ '--help[Show help for command]' \ '(-R --repo)'{-R,--repo}'[Select another repository using the `OWNER/REPO` format]:' } @@ -283,7 +293,8 @@ function _gh_issue_list { } function _gh_issue_reopen { - _arguments \ + _arguments -C \ + "1:Issue:(($(__issue_numbers --state closed)))" \ '--help[Show help for command]' \ '(-R --repo)'{-R,--repo}'[Select another repository using the `OWNER/REPO` format]:' } @@ -295,7 +306,8 @@ function _gh_issue_status { } function _gh_issue_view { - _arguments \ + _arguments -C \ + "1:Issue:(($(__issue_numbers --state all)))" \ '(-w --web)'{-w,--web}'[Open an issue in the browser]' \ '--help[Show help for command]' \ '(-R --repo)'{-R,--repo}'[Select another repository using the `OWNER/REPO` format]:'