Subversion Repositories configs

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 - 1
# bash completion for yum
2
 
3
# arguments:
4
#   1 = argument to "yum list" (all, available, updates etc)
5
#   2 = current word to be completed
6
_yum_list()
7
{
8
    if [ "$1" = all ] ; then
9
        # Try to strip in between headings like "Available Packages" - would
10
        # be nice if e.g. -d 0 did that for us.  This will obviously only work
11
        # for English :P
12
        COMPREPLY=( "${COMPREPLY[@]}"
13
            $( ${yum:-yum} -d 0 -C list $1 "$2*" 2>/dev/null | \
14
                sed -ne '/^Available /d' -e '/^Installed /d' -e '/^Updated /d' \
15
                -e 's/[[:space:]].*//p' ) )
16
    else
17
        # Drop first line (e.g. "Updated Packages") - would be nice if e.g.
18
        # -d 0 did that for us.
19
        COMPREPLY=( "${COMPREPLY[@]}"
20
            $( ${yum:-yum} -d 0 -C list $1 "$2*" 2>/dev/null | \
21
                sed -ne 1d -e 's/[[:space:]].*//p' ) )
22
    fi
23
}
24
 
25
# arguments:
26
#   1 = argument to "yum repolist" (enabled, disabled etc)
27
#   2 = current word to be completed
28
_yum_repolist()
29
{
30
    # TODO: add -d 0 when http://yum.baseurl.org/ticket/29 is fixed
31
    #       (for now --noplugins is used to get rid of "Loaded plugins: ...")
32
    # Drop first ("repo id      repo name") and last ("repolist: ...") rows -
33
    # would be nice if e.g. -d 0 did that for us.
34
    COMPREPLY=( "${COMPREPLY[@]}"
35
        $( compgen -W "$( ${yum:-yum} --noplugins -C repolist $1 2>/dev/null | \
36
            sed -ne '/^repo\s\{1,\}id/d' -e '/^repolist:/d' \
37
            -e 's/[[:space:]].*//p' )" -- "$2" ) )
38
}
39
 
40
# arguments:
41
#   1 = argument to "yum grouplist" (usually empty (""), or hidden)
42
#   2 = current word to be completed
43
_yum_grouplist()
44
{
45
    local IFS=$'\n'
46
    # TODO: add -d 0 when http://yum.baseurl.org/ticket/29 is fixed
47
    COMPREPLY=( $( compgen -W "$( ${yum:-yum} -C grouplist $1 "$2*" \
48
        2>/dev/null | sed -ne 's/^[[:space:]]\{1,\}\(.\{1,\}\)/\1/p' )" \
49
        -- "$2" ) )
50
}
51
 
52
# arguments:
53
#   1 = 1 or 0 to list enabled or disabled plugins
54
#   2 = current word to be completed
55
_yum_plugins()
56
{
57
    local val
58
    [ $1 = 1 ] && val='\(1\|yes\|true\|on\)' || val='\(0\|no\|false\|off\)'
59
    COMPREPLY=( "${COMPREPLY[@]}"
60
        $( compgen -W '$( command grep -il "^\s*enabled\s*=\s*$val" \
61
            /etc/yum/pluginconf.d/*.conf 2>/dev/null \
62
            | sed -ne "s|^.*/\([^/]\{1,\}\)\.conf$|\1|p" )' -- "$2" ) )
63
}
64
 
65
# arguments:
66
#   1 = current word to be completed
67
_yum_binrpmfiles()
68
{
69
    COMPREPLY=( "${COMPREPLY[@]}"
70
        $( compgen -f -o plusdirs -X '!*.rpm' -- "$1" ) )
71
    COMPREPLY=( $( compgen -W '"${COMPREPLY[@]}"' -X '*.src.rpm' ) )
72
    COMPREPLY=( $( compgen -W '"${COMPREPLY[@]}"' -X '*.nosrc.rpm' ) )
73
}
74
 
75
_yum_baseopts()
76
{
77
    local opts='--help --tolerant --cacheonly --config --randomwait
78
        --debuglevel --showduplicates --errorlevel --rpmverbosity --quiet
79
        --verbose --assumeyes --version --installroot --enablerepo
80
        --disablerepo --exclude --disableexcludes --obsoletes --noplugins
81
        --nogpgcheck --skip-broken --color --releasever --setopt'
82
    [[ $COMP_LINE == *--noplugins* ]] || \
83
        opts="$opts --disableplugin --enableplugin"
84
    printf %s "$opts"
85
}
86
 
87
# arguments:
88
#   1 = current word to be completed
89
#   2 = previous word
90
# return 0 if no more completions should be sought, 1 otherwise
91
_yum_complete_baseopts()
92
{
93
    local split=false
94
    type _split_longopt &>/dev/null && _split_longopt && split=true
95
 
96
    case $2 in
97
 
98
        -d|--debuglevel|-e|--errorlevel)
99
            COMPREPLY=( $( compgen -W '0 1 2 3 4 5 6 7 8 9 10' -- "$1" ) )
100
            return 0
101
            ;;
102
 
103
        --rpmverbosity)
104
            COMPREPLY=( $( compgen -W 'info critical emergency error warn
105
                debug' -- "$1" ) )
106
            return 0
107
            ;;
108
 
109
        -c|--config)
110
            COMPREPLY=( $( compgen -f -o plusdirs -X "!*.conf" -- "$1" ) )
111
            return 0
112
            ;;
113
 
114
        --installroot|--downloaddir)
115
            COMPREPLY=( $( compgen -d -- "$1" ) )
116
            return 0
117
            ;;
118
 
119
        --enablerepo)
120
            _yum_repolist disabled "$1"
121
            return 0
122
            ;;
123
 
124
        --disablerepo)
125
            _yum_repolist enabled "$1"
126
            return 0
127
            ;;
128
 
129
        --disableexcludes)
130
            _yum_repolist all "$1"
131
            COMPREPLY=( $( compgen -W '${COMPREPLY[@]} all main' -- "$1" ) )
132
            return 0
133
            ;;
134
 
135
        --enableplugin)
136
            _yum_plugins 0 "$1"
137
            return 0
138
            ;;
139
 
140
        --disableplugin)
141
            _yum_plugins 1 "$1"
142
            return 0
143
            ;;
144
 
145
        --color)
146
            COMPREPLY=( $( compgen -W 'always auto never' -- "$1" ) )
147
            return 0
148
            ;;
149
 
150
        -R|--randomwait|-x|--exclude|-h|--help|--version|--releasever|--cve|\
151
        --bz|--advisory|--tmprepo|--verify-filenames|--setopt)
152
            return 0
153
            ;;
154
 
155
        --download-order)
156
            COMPREPLY=( $( compgen -W 'default smallestfirst largestfirst' \
157
                -- "$1" ) )
158
            return 0
159
            ;;
160
 
161
        --override-protection)
162
            _yum_list installed "$1"
163
            return 0
164
            ;;
165
 
166
        --verify-configuration-files)
167
            COMPREPLY=( $( compgen -W '1 0' -- "$1" ) )
168
            return 0
169
            ;;
170
    esac
171
 
172
    $split && return 0 || return 1
173
}
174
 
175
_yum()
176
{
177
    COMPREPLY=()
178
    local yum=$1
179
    local cur prev
180
    local -a words
181
    if type _get_comp_words_by_ref &>/dev/null ; then
182
        _get_comp_words_by_ref cur prev words
183
    else
184
        cur=$2 prev=$3 words=("${COMP_WORDS[@]}")
185
    fi
186
    # Commands offered as completions
187
    local cmds=( check check-update clean deplist distro-sync downgrade
188
        groupinfo groupinstall grouplist groupremove help history info install
189
        list makecache provides reinstall remove repolist resolvedep search
190
        shell update upgrade version )
191
 
192
    local i c cmd subcmd
193
    for (( i=1; i < ${#words[@]}-1; i++ )) ; do
194
        [[ -n $cmd ]] && subcmd=${words[i]} && break
195
        # Recognize additional commands and aliases
196
        for c in ${cmds[@]} check-rpmdb distribution-synchronization erase \
197
            groupupdate grouperase localinstall localupdate whatprovides ; do
198
            [[ ${words[i]} == $c ]] && cmd=$c && break
199
        done
200
    done
201
 
202
    case $cmd in
203
 
204
        check|check-rpmdb)
205
            COMPREPLY=( $( compgen -W 'dependencies duplicates all' \
206
                -- "$cur" ) )
207
            return 0
208
            ;;
209
 
210
        check-update|grouplist|makecache|provides|whatprovides|resolvedep|\
211
        search)
212
            return 0
213
            ;;
214
 
215
        clean)
216
            if [ "$prev" = clean ] ; then
217
                COMPREPLY=( $( compgen -W 'expire-cache packages headers
218
                    metadata cache dbcache all' -- "$cur" ) )
219
            fi
220
            return 0
221
            ;;
222
 
223
        deplist)
224
            COMPREPLY=( $( compgen -f -o plusdirs -X '!*.[rs]pm' -- "$cur" ) )
225
            [[ "$cur" == */* ]] || _yum_list all "$cur"
226
            return 0
227
            ;;
228
 
229
        downgrade|reinstall)
230
            _yum_binrpmfiles "$cur"
231
            [[ "$cur" == */* ]] || _yum_list installed "$cur"
232
            return 0
233
            ;;
234
 
235
        erase|remove|distro-sync|distribution-synchronization)
236
            _yum_list installed "$cur"
237
            return 0
238
            ;;
239
 
240
        group*)
241
            _yum_grouplist "" "$cur"
242
            return 0
243
            ;;
244
 
245
        help)
246
            if [ "$prev" = help ] ; then
247
                COMPREPLY=( $( compgen -W '${cmds[@]}' -- "$cur" ) )
248
            fi
249
            return 0
250
            ;;
251
 
252
        history)
253
            case $prev in
254
                history)
255
                    COMPREPLY=( $( compgen -W 'info list summary undo redo
256
                        new addon-info package-list' -- "$cur" ) )
257
                    ;;
258
                undo|redo|repeat|addon|addon-info)
259
                    COMPREPLY=( $( compgen -W "last $( $yum -d 0 -C history \
260
                        2>/dev/null | \
261
                        sed -ne 's/^[[:space:]]*\([0-9]\{1,\}\).*/\1/p' )" \
262
                        -- "$cur" ) )
263
                    ;;
264
            esac
265
            case $subcmd in
266
                package-list|pkg|pkgs|pkg-list|pkgs-list|package|packages|\
267
                packages-list)
268
                    _yum_list installed "$cur"
269
                    ;;
270
            esac
271
            return 0
272
            ;;
273
 
274
        info)
275
            _yum_list all "$cur"
276
            return 0
277
            ;;
278
 
279
        install)
280
            _yum_binrpmfiles "$cur"
281
            [[ "$cur" == */* ]] || _yum_list available "$cur"
282
            return 0
283
            ;;
284
 
285
        list)
286
            if [ "$prev" = list ] ; then
287
                COMPREPLY=( $( compgen -W 'all available updates installed
288
                    extras obsoletes recent' -- "$cur" ) )
289
            fi
290
            return 0
291
            ;;
292
 
293
        localinstall|localupdate)
294
            _yum_binrpmfiles "$cur"
295
            return 0
296
            ;;
297
 
298
        repolist)
299
            if [ "$prev" = repolist ] ; then
300
                COMPREPLY=( $( compgen -W 'all enabled disabled' -- "$cur" ) )
301
            fi
302
            return 0
303
            ;;
304
 
305
        shell)
306
            if [ "$prev" = shell ] ; then
307
                COMPREPLY=( $( compgen -f -o plusdirs -- "$cur" ) )
308
            fi
309
            return 0
310
            ;;
311
 
312
        update|upgrade)
313
            _yum_binrpmfiles "$cur"
314
            [[ "$cur" == */* ]] || _yum_list updates "$cur"
315
            return 0
316
            ;;
317
        version)
318
            if [ "$prev" = version ] ; then
319
                COMPREPLY=( $( compgen -W 'all installed available nogroups
320
                    grouplist groupinfo' -- "$cur" ) )
321
            fi
322
            return 0
323
            ;;
324
    esac
325
 
326
    _yum_complete_baseopts "$cur" "$prev" && return 0
327
 
328
    COMPREPLY=( $( compgen -W '$( _yum_baseopts ) ${cmds[@]}' -- "$cur" ) )
329
} &&
330
complete -F _yum -o filenames yum yummain.py
331
 
332
# Local variables:
333
# mode: shell-script
334
# sh-basic-offset: 4
335
# sh-indent-comment: t
336
# indent-tabs-mode: nil
337
# End:
338
# ex: ts=4 sw=4 et filetype=sh