]> TLD Linux GIT Repositories - tld-ftp-admin.git/blob - shell/bash-completion.sh
- raw from PLD
[tld-ftp-admin.git] / shell / bash-completion.sh
1 # various completions for pld-ftp-admin tools
2 # Author: Elan Ruusamäe <glen@pld-linux.org>
3
4 # return list of pld ftp trees
5 _pfa_tree() {
6     local cur="$1"
7     if [ -z "$PFA_TREES" ]; then
8         local d
9         local -a trees
10         for d in  ~/ftp/*/; do
11             d=${d%/}
12             d=${d##*/}
13             PFA_TREES+=" $d"
14         done
15         # kill leading space
16         PFA_TREES=${PFA_TREES# }
17     fi
18
19     COMPREPLY=( $( compgen -W "$PFA_TREES" -- "$cur" ) )
20 }
21
22 # return list of files in a tree
23 _pfa_tree_files() {
24     local tree="$1" cur="$2" file i
25     local dir=~/ftp/$tree/SRPMS/.metadata
26
27     # generate reply from dir
28     COMPREPLY=( $( compgen -f -X "*.(src.rpm.info)" -- "$dir/$cur" ) )
29     # filter out dirname from results
30     for (( i=0; i < ${#COMPREPLY[@]}; i++ )); do
31         file=${COMPREPLY[$i]##*/}
32         COMPREPLY[$i]=$file
33     done
34 }
35
36 have pfa-genindex &&
37 _pfa-genindex()
38 {
39     local cur
40
41     COMPREPLY=()
42     _get_comp_words_by_ref cur
43
44     if [[ "$cur" == -* ]]; then
45         COMPREPLY=( $( compgen -W '\
46             -q --quiet --index \
47             --nopoldek --noyum --norpmrepo \
48             --poldek --yum --rpmrepo \
49             ' \
50             -- "$cur" ) )
51     else
52         _pfa_tree "$cur"
53     fi
54 } &&
55 complete -F _pfa-genindex pfa-genindex
56
57 have pfa-lintpkg &&
58 _pfa-lintpkg()
59 {
60     local cur arg
61
62     COMPREPLY=()
63     _get_comp_words_by_ref cur
64
65     if [[ "$cur" == -* ]]; then
66         COMPREPLY=( $( compgen -W '-q -s --quiet' -- "$cur" ) )
67     else
68         # The first argument is an tree; the rest are files in a dir
69         _count_args :
70
71         if [[ $args == 1 ]]; then
72             _pfa_tree "$cur"
73         else
74             _get_first_arg
75             _pfa_tree_files "$arg" "$cur"
76         fi
77     fi
78 } &&
79 complete -F _pfa-lintpkg pfa-lintpkg
80
81 have pfa-signpkg &&
82 _pfa-signpkg()
83 {
84     local cur
85
86     COMPREPLY=()
87     _get_comp_words_by_ref cur
88
89     # The first argument is an tree; the rest are files in a dir
90     _count_args :
91
92     if [[ $args == 1 ]]; then
93         _pfa_tree "$cur"
94     else
95         _pfa_tree_files "${COMP_WORDS[1]}" "$cur"
96     fi
97 } &&
98 complete -F _pfa-signpkg pfa-signpkg pfa-rmpkg
99
100 have pfa-mvpkg &&
101 _pfa-mvpkg()
102 {
103     local cur
104
105     COMPREPLY=()
106     _get_comp_words_by_ref cur
107
108     # The first two arguments are tree names; the rest are files in a dir
109     _count_args :
110
111     if [[ $args == 1 ]] || [[ $args == 2 ]]; then
112         _pfa_tree "$cur"
113     else
114         _pfa_tree_files "${COMP_WORDS[1]}" "$cur"
115     fi
116 } &&
117 complete -F _pfa-mvpkg pfa-mvpkg pfa-testmvpkg
118
119 # Local variables:
120 # mode: shell-script
121 # sh-basic-offset: 4
122 # sh-indent-comment: t
123 # indent-tabs-mode: nil
124 # End:
125 # ex: ts=4 sw=4 et filetype=sh