Subversion Repositories configs

Rev

Rev 3 | Details | Compare with Previous | 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
33 - 79
        --verbose --assumeyes --assumeno --version --installroot --enablerepo
3 - 80
        --disablerepo --exclude --disableexcludes --obsoletes --noplugins
33 - 81
        --nogpgcheck --skip-broken --color --releasever --setopt --downloadonly
82
        --downloaddir'
3 - 83
    [[ $COMP_LINE == *--noplugins* ]] || \
84
        opts="$opts --disableplugin --enableplugin"
85
    printf %s "$opts"
86
}
87
 
88
# arguments:
89
#   1 = current word to be completed
90
#   2 = previous word
91
# return 0 if no more completions should be sought, 1 otherwise
92
_yum_complete_baseopts()
93
{
94
    local split=false
95
    type _split_longopt &>/dev/null && _split_longopt && split=true
96
 
97
    case $2 in
98
 
99
        -d|--debuglevel|-e|--errorlevel)
100
            COMPREPLY=( $( compgen -W '0 1 2 3 4 5 6 7 8 9 10' -- "$1" ) )
101
            return 0
102
            ;;
103
 
104
        --rpmverbosity)
105
            COMPREPLY=( $( compgen -W 'info critical emergency error warn
106
                debug' -- "$1" ) )
107
            return 0
108
            ;;
109
 
110
        -c|--config)
111
            COMPREPLY=( $( compgen -f -o plusdirs -X "!*.conf" -- "$1" ) )
112
            return 0
113
            ;;
114
 
115
        --installroot|--downloaddir)
116
            COMPREPLY=( $( compgen -d -- "$1" ) )
117
            return 0
118
            ;;
119
 
120
        --enablerepo)
121
            _yum_repolist disabled "$1"
122
            return 0
123
            ;;
124
 
125
        --disablerepo)
126
            _yum_repolist enabled "$1"
127
            return 0
128
            ;;
129
 
130
        --disableexcludes)
131
            _yum_repolist all "$1"
132
            COMPREPLY=( $( compgen -W '${COMPREPLY[@]} all main' -- "$1" ) )
133
            return 0
134
            ;;
135
 
136
        --enableplugin)
137
            _yum_plugins 0 "$1"
138
            return 0
139
            ;;
140
 
141
        --disableplugin)
142
            _yum_plugins 1 "$1"
143
            return 0
144
            ;;
145
 
146
        --color)
147
            COMPREPLY=( $( compgen -W 'always auto never' -- "$1" ) )
148
            return 0
149
            ;;
150
 
151
        -R|--randomwait|-x|--exclude|-h|--help|--version|--releasever|--cve|\
152
        --bz|--advisory|--tmprepo|--verify-filenames|--setopt)
153
            return 0
154
            ;;
155
 
156
        --download-order)
157
            COMPREPLY=( $( compgen -W 'default smallestfirst largestfirst' \
158
                -- "$1" ) )
159
            return 0
160
            ;;
161
 
162
        --override-protection)
163
            _yum_list installed "$1"
164
            return 0
165
            ;;
166
 
167
        --verify-configuration-files)
168
            COMPREPLY=( $( compgen -W '1 0' -- "$1" ) )
169
            return 0
170
            ;;
171
    esac
172
 
173
    $split && return 0 || return 1
174
}
175
 
176
_yum()
177
{
178
    COMPREPLY=()
179
    local yum=$1
180
    local cur prev
181
    local -a words
182
    if type _get_comp_words_by_ref &>/dev/null ; then
183
        _get_comp_words_by_ref cur prev words
184
    else
185
        cur=$2 prev=$3 words=("${COMP_WORDS[@]}")
186
    fi
187
    # Commands offered as completions
188
    local cmds=( check check-update clean deplist distro-sync downgrade
189
        groupinfo groupinstall grouplist groupremove help history info install
190
        list makecache provides reinstall remove repolist resolvedep search
191
        shell update upgrade version )
192
 
193
    local i c cmd subcmd
194
    for (( i=1; i < ${#words[@]}-1; i++ )) ; do
195
        [[ -n $cmd ]] && subcmd=${words[i]} && break
196
        # Recognize additional commands and aliases
197
        for c in ${cmds[@]} check-rpmdb distribution-synchronization erase \
198
            groupupdate grouperase localinstall localupdate whatprovides ; do
199
            [[ ${words[i]} == $c ]] && cmd=$c && break
200
        done
201
    done
202
 
203
    case $cmd in
204
 
205
        check|check-rpmdb)
206
            COMPREPLY=( $( compgen -W 'dependencies duplicates all' \
207
                -- "$cur" ) )
208
            return 0
209
            ;;
210
 
211
        check-update|grouplist|makecache|provides|whatprovides|resolvedep|\
212
        search)
213
            return 0
214
            ;;
215
 
216
        clean)
217
            if [ "$prev" = clean ] ; then
218
                COMPREPLY=( $( compgen -W 'expire-cache packages headers
219
                    metadata cache dbcache all' -- "$cur" ) )
220
            fi
221
            return 0
222
            ;;
223
 
224
        deplist)
225
            COMPREPLY=( $( compgen -f -o plusdirs -X '!*.[rs]pm' -- "$cur" ) )
226
            [[ "$cur" == */* ]] || _yum_list all "$cur"
227
            return 0
228
            ;;
229
 
230
        downgrade|reinstall)
231
            _yum_binrpmfiles "$cur"
232
            [[ "$cur" == */* ]] || _yum_list installed "$cur"
233
            return 0
234
            ;;
235
 
236
        erase|remove|distro-sync|distribution-synchronization)
237
            _yum_list installed "$cur"
238
            return 0
239
            ;;
240
 
241
        group*)
242
            _yum_grouplist "" "$cur"
243
            return 0
244
            ;;
245
 
246
        help)
247
            if [ "$prev" = help ] ; then
248
                COMPREPLY=( $( compgen -W '${cmds[@]}' -- "$cur" ) )
249
            fi
250
            return 0
251
            ;;
252
 
253
        history)
254
            case $prev in
255
                history)
256
                    COMPREPLY=( $( compgen -W 'info list summary undo redo
257
                        new addon-info package-list' -- "$cur" ) )
258
                    ;;
259
                undo|redo|repeat|addon|addon-info)
260
                    COMPREPLY=( $( compgen -W "last $( $yum -d 0 -C history \
261
                        2>/dev/null | \
262
                        sed -ne 's/^[[:space:]]*\([0-9]\{1,\}\).*/\1/p' )" \
263
                        -- "$cur" ) )
264
                    ;;
265
            esac
266
            case $subcmd in
267
                package-list|pkg|pkgs|pkg-list|pkgs-list|package|packages|\
268
                packages-list)
269
                    _yum_list installed "$cur"
270
                    ;;
271
            esac
272
            return 0
273
            ;;
274
 
275
        info)
276
            _yum_list all "$cur"
277
            return 0
278
            ;;
279
 
280
        install)
281
            _yum_binrpmfiles "$cur"
282
            [[ "$cur" == */* ]] || _yum_list available "$cur"
283
            return 0
284
            ;;
285
 
286
        list)
287
            if [ "$prev" = list ] ; then
288
                COMPREPLY=( $( compgen -W 'all available updates installed
289
                    extras obsoletes recent' -- "$cur" ) )
290
            fi
291
            return 0
292
            ;;
293
 
294
        localinstall|localupdate)
295
            _yum_binrpmfiles "$cur"
296
            return 0
297
            ;;
298
 
299
        repolist)
300
            if [ "$prev" = repolist ] ; then
301
                COMPREPLY=( $( compgen -W 'all enabled disabled' -- "$cur" ) )
302
            fi
303
            return 0
304
            ;;
305
 
306
        shell)
307
            if [ "$prev" = shell ] ; then
308
                COMPREPLY=( $( compgen -f -o plusdirs -- "$cur" ) )
309
            fi
310
            return 0
311
            ;;
312
 
313
        update|upgrade)
314
            _yum_binrpmfiles "$cur"
315
            [[ "$cur" == */* ]] || _yum_list updates "$cur"
316
            return 0
317
            ;;
318
        version)
319
            if [ "$prev" = version ] ; then
320
                COMPREPLY=( $( compgen -W 'all installed available nogroups
321
                    grouplist groupinfo' -- "$cur" ) )
322
            fi
323
            return 0
324
            ;;
325
    esac
326
 
327
    _yum_complete_baseopts "$cur" "$prev" && return 0
328
 
329
    COMPREPLY=( $( compgen -W '$( _yum_baseopts ) ${cmds[@]}' -- "$cur" ) )
330
} &&
331
complete -F _yum -o filenames yum yummain.py
332
 
333
# Local variables:
334
# mode: shell-script
335
# sh-basic-offset: 4
336
# sh-indent-comment: t
337
# indent-tabs-mode: nil
338
# End:
339
# ex: ts=4 sw=4 et filetype=sh