]> git.ozlabs.org Git - bitfield/blob - bitfield-completions.sh
Add global configs
[bitfield] / bitfield-completions.sh
1 # completion for bitfield program
2 _bitfield_list() {
3         bitfield --list | awk '{print $1}'
4 }
5
6 _bitfield() {
7         local cur prev
8
9         COMPREPLY=()
10         cur=${COMP_WORDS[COMP_CWORD]}
11         prev=${COMP_WORDS[COMP_CWORD-1]}
12
13         # help, search, list: no completions
14         if [[ "$prev" == '-h' || "$prev" == '-s' || "$prev" == '-l' ]]
15         then
16                 return 0
17         fi
18
19         opts="--help --search --list --non-zero"
20
21         # complete -* with long options.
22         if [[ "$cur" == -* ]]
23         then
24                 COMPREPLY=($(compgen -W "$opts" -- $cur))
25                 return 0
26         fi
27
28         # first parameter on line - complete with options + list of bitfields
29         # FIXME: presence of -n will disable this...
30         if [ $COMP_CWORD -eq 1 ]
31         then
32                 COMPREPLY=($(compgen -W "$opts $(_bitfield_list)" -- $cur))
33                 return 0
34         fi
35 }
36
37 complete -F _bitfield filenames bitfield