blob: 929346d09c7cf03708790cbb57f314d4d9a5032e (
plain)
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
|
# bash completion for gitctl
# install: cp completions/gitctl.bash /etc/bash_completion.d/gitctl
# or: source completions/gitctl.bash (from ~/.bashrc)
_gitctl() {
local cur prev words cword
_init_completion 2>/dev/null || {
# minimal fallback if bash-completion's _init_completion is absent
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
words=("${COMP_WORDS[@]}")
cword=$COMP_CWORD
}
# global -y/--yes may sit before the subcommand; skip it so group/action and
# the cword positions below line up whether or not it is present.
local off=0
[[ ${words[1]} == "-y" || ${words[1]} == "--yes" ]] && off=1
local group=${words[1+off]} action=${words[2+off]}
local cword=$((cword - off))
# complete section names from the live server (one ssh call). Only when the
# previous word is --section, so we do not pay it on every Tab.
if [[ $prev == "--section" ]]; then
local secs
secs=$(gitctl sections list 2>/dev/null)
local IFS=$'\n'
COMPREPLY=($(compgen -W "$secs" -- "$cur"))
return
fi
case $cword in
1)
COMPREPLY=($(compgen -W "-y --yes sections sync repo" -- "$cur"))
return ;;
2)
case $group in
sections) COMPREPLY=($(compgen -W "list add" -- "$cur")) ;;
repo) COMPREPLY=($(compgen -W "create list desc add-remote delete" -- "$cur")) ;;
esac
return ;;
esac
# flags, by subcommand
if [[ $cur == -* ]]; then
case "$group $action" in
"repo create") COMPREPLY=($(compgen -W "--section --desc --owner" -- "$cur")) ;;
"repo add-remote") COMPREPLY=($(compgen -W "--remote-name" -- "$cur")) ;;
esac
return
fi
}
complete -F _gitctl gitctl
|