-
Notifications
You must be signed in to change notification settings - Fork 1
/
bitbutler.completion
66 lines (57 loc) · 2.11 KB
/
bitbutler.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env bash
#
# Bash completion for bitbutler
_bitbutler_completion()
{
local commands options pages cmd
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
commands=$(bitbutler help | awk '/Commands/,/Options/' | awk '/^\s{4}\x1b\S+\s*/ {print $1}' | sed 's/\x1b\[[0-9;]*m//g')
pages="apidoc dashboard"
# not local for caching
bbc_repos=
if [[ ${cur} == -* ]] ; then
options="$(bitbutler help | grep -zoE 'Options.*' | grep -aP '^\s{4}\x1b' | awk 'BEGIN {FS = "[ \x1b]+" } {print $3}')"
COMPREPLY=( $(compgen -W "${options}" -- ${cur}) )
return 0
else
if [[ ${COMP_CWORD} == 1 ]]; then
COMPREPLY=( $(compgen -W "${commands}" -- ${cur}) )
return 0
elif [[ ${COMP_CWORD} == 2 ]]; then
case "$prev" in
open)
COMPREPLY=( $(compgen -W "${pages}" -- ${cur}) )
;;
branch)
if [[ -z "$bbc_repos" ]]; then
bbc_repos="$(bitbutler repo list)"
fi
COMPREPLY=( $(compgen -W "$bbc_repos" -- ${cur}) )
;;
deploykey|restriction|reviewer|repo|webhook)
COMPREPLY=( $(compgen -W "add delete list" -- ${cur}) )
;;
pullrequest)
COMPREPLY=( $(compgen -W "approve list unapprove" -- ${cur}) )
;;
commit)
COMPREPLY=( $(compgen -W "approve unapprove" -- ${cur}) )
;;
esac
elif [[ ${COMP_CWORD} == 3 ]]; then
cmd="${COMP_WORDS[COMP_CWORD-2]}"
if [[ -z "$bbc_repos" ]]; then
bbc_repos="$(bitbutler repo list)"
fi
case "$cmd" in
commit|deploykey|pullrequest|restriction|reviewer|webhook)
COMPREPLY=( $(compgen -W "$bbc_repos" -- ${cur}) )
;;
esac
fi
fi
return 0
}
complete -F _bitbutler_completion bitbutler 2>/dev/null