blob: 0b680dd7d098d3fc479550e74790eeb048d81e66 (
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
|
# 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
}
local group=${words[1]} action=${words[2]}
# 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 "sections sync repo" -- "$cur"))
return ;;
2)
case $group in
sections) COMPREPLY=($(compgen -W "list add" -- "$cur")) ;;
repo) COMPREPLY=($(compgen -W "create desc add-remote" -- "$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
|