Skip to content

Commit b00ff27

Browse files
committed
Add draft of ZSH completion plugin
It's quite basic and I cannot really do what I would like, but it's good enough.
1 parent 3419a08 commit b00ff27

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed

MANIFEST.in

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ include README.rst
77
graft src/cogite
88

99
prune docs
10+
prune extra
1011
prune tests
1112
exclude .pylintrc
1213
exclude .readthedocs.yaml

docs/features.rst

+8
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,11 @@ Conflict resolution
3636
-------------------
3737

3838
FIXME
39+
40+
41+
.. _shell_completion:
42+
43+
Shell completion
44+
----------------
45+
46+
FIXME: document ZSH completion

extra/completion.zsh

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#compdef cogite
2+
3+
_cogite() {
4+
if [[ ${CURRENT} -eq 2 ]]; then
5+
COMPREPLY=($(compgen -W "auth ci pr status" -- ${cur}))
6+
elif [[ ${CURRENT} -eq 3 ]]; then
7+
local cmd=${COMP_WORDS[1]}
8+
case ${cmd} in
9+
auth)
10+
COMPREPLY=($(compgen -W "add delete" -- ${cur}))
11+
;;
12+
ci)
13+
COMPREPLY=($(compgen -W "browse" -- ${cur}))
14+
;;
15+
pr)
16+
COMPREPLY=($(compgen -W "add browse draft merge ready rebase reqreview" -- ${cur}))
17+
;;
18+
status)
19+
COMPREPLY=($(compgen -W "--poll" -- ${cur}))
20+
;;
21+
esac
22+
elif [[ ${CURRENT} -gt 3 ]]; then
23+
local cmd="${COMP_WORDS[1]} ${COMP_WORDS[2]}"
24+
case ${cmd} in
25+
"auth add")
26+
COMPREPLY=($(compgen -W "--help" -- ${cur}))
27+
;;
28+
"auth delete")
29+
COMPREPLY=($(compgen -W "--help" -- ${cur}))
30+
;;
31+
"ci browse")
32+
COMPREPLY=($(compgen -W "--help" -- ${cur}))
33+
;;
34+
"pr add")
35+
COMPREPLY=($(compgen -W "--help --base --draft" -- ${cur}))
36+
# FIXME (dbaty, 2021-12-04) : I would like to use `_arguments`
37+
# to have more detailed auto-completion, with this:
38+
# _arguments \
39+
# '--base[branch where changes should be applied]' \
40+
# '--draft[mark as a draft pull request]'
41+
# ... but I get the following error:
42+
# _arguments:34: bad output format specification
43+
# _arguments:366: bad math expression: operator expected at `descrs'
44+
;;
45+
"pr browse")
46+
COMPREPLY=($(compgen -W "--help --browse" -- ${cur}))
47+
;;
48+
"pr draft")
49+
COMPREPLY=($(compgen -W "--help --base" -- ${cur}))
50+
;;
51+
"pr merge")
52+
COMPREPLY=($(compgen -W "--help" -- ${cur}))
53+
;;
54+
"pr ready")
55+
COMPREPLY=($(compgen -W "--help" -- ${cur}))
56+
;;
57+
"pr rebase")
58+
COMPREPLY=($(compgen -W "--help" -- ${cur}))
59+
;;
60+
"pr reqreview")
61+
COMPREPLY=($(compgen -W "--help" -- ${cur}))
62+
;;
63+
esac
64+
fi
65+
}
66+
67+
complete -F _cogite cogite

0 commit comments

Comments
 (0)