-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate-pr.completion
33 lines (27 loc) · 1.07 KB
/
create-pr.completion
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env bash
#
# Provides autocompletion for the `create-pr` command.
function _create-pr() {
cur=${COMP_WORDS[${COMP_CWORD}]}
# create-pr [-b <base-branch>] [<label> ...]
options="-b"
if [[ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" != "true" ]]; then
# Not in a git repository
return
fi
# create-pr [-b <base-branch>] [<label> ...]
if [[ ${COMP_CWORD} -eq 2 && "${cur}" == "-b" ]]; then
# Complete the base branch
branches=$(bkt --discard-failures -- gh api /repos/$(git remote get-url origin | sed 's/^git@github.com://' | sed 's/.git$//g')/branches --jq '.[].name')
COMPREPLY=($(compgen -W "${branches}" -- "${cur}"))
else
# Complete the labels
labels=$(bkt --discard-failures -- gh label list --json name --jq '.[].name' 2> /dev/null)
if [[ ${COMP_CWORD} -eq 1 ]]; then
COMPREPLY=($(compgen -W "${labels} ${options}" -- "${cur}"))
else
COMPREPLY=($(compgen -W "${labels}" -- "${cur}"))
fi
fi
}
complete -F _create-pr create-pr