]> TLD Linux GIT Repositories - packages/bash-completion.git/blob - builder.bash-completion
- from PLD
[packages/bash-completion.git] / builder.bash-completion
1 # PLD Linux builder(1) script completion
2
3 # get active spec file from commandline
4 # caller should make $spec local variable
5 # TODO: it gets it wrong if some option arg is found before spec itself
6 _builder_get_spec()
7 {
8         local i
9         spec=
10         for (( i=1; i < ${#words[@]}-1; i++ )); do
11                 if [[ ${words[i]} != -* ]]; then
12                         spec=${words[i]}
13                         break
14                 fi
15         done
16         [[ ! -f $spec ]] && return 0
17 }
18
19 _builder()
20 {
21         local cur prev words cword
22         _init_completion || return
23
24         case $prev in
25         -r)
26                 COMPREPLY=( $( compgen -W '$( git tag )' -- "$cur" ) )
27                 return 0
28                 ;;
29         --with|--without)
30                 local spec bconds
31                 _builder_get_spec
32                 bconds=$(
33                         awk '
34                         /^%changelog/ { exit }
35                         /^%bcond_with/{
36                                 print $2
37                         }' $spec
38                 )
39                 COMPREPLY=( $( compgen -W "$bconds" -- "$cur" ) )
40                 return 0
41                 ;;
42         esac
43
44         if [[ $cur == -* ]]; then
45                 COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
46         else
47                 _filedir spec
48         fi
49 } &&
50 complete -F _builder builder