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