- some rpm completion speed-ups, adapted from a patch by Dag Wieers

<dag@wieers.com>
This commit is contained in:
ianmacd 2003-04-29 05:28:10 +00:00
parent 9fd0bc1d2e
commit eb2a24cda3

View File

@ -1,6 +1,6 @@
# bash_completion - some programmable completion functions for bash 2.05b # bash_completion - some programmable completion functions for bash 2.05b
# #
# $Id: bash_completion,v 1.557 2003/04/29 02:24:20 ianmacd Exp $ # $Id: bash_completion,v 1.558 2003/04/29 07:28:10 ianmacd Exp $
# #
# Copyright (C) Ian Macdonald <ian@caliban.org> # Copyright (C) Ian Macdonald <ian@caliban.org>
# #
@ -1257,12 +1257,12 @@ _rpm_installed_packages()
if [ -r /var/log/rpmpkgs -a \ if [ -r /var/log/rpmpkgs -a \
/var/log/rpmpkgs -nt /var/lib/rpm/Packages ]; then /var/log/rpmpkgs -nt /var/lib/rpm/Packages ]; then
# using RHL 7.2 - this is quicker than querying the DB # using RHL 7.2 or later - this is quicker than querying the DB
COMPREPLY=( $( sed -ne \ COMPREPLY=( $( sed -ne \
's|^\('$cur'.*\)-[0-9a-zA-Z._]\+-[0-9a-z.@]\+.*\.rpm$|\1|p' \ 's|^\('$cur'.*\)-[0-9a-zA-Z._]\+-[0-9a-z.@]\+.*\.rpm$|\1|p' \
/var/log/rpmpkgs ) ) /var/log/rpmpkgs ) )
else else
COMPREPLY=( $( rpm -qa | sed -ne \ COMPREPLY=( $( rpm -qa $options | sed -ne \
's|^\('$cur'.*\)-[0-9a-zA-Z._]\+-[0-9a-z.@]\+$|\1|p' ) ) 's|^\('$cur'.*\)-[0-9a-zA-Z._]\+-[0-9a-z.@]\+$|\1|p' ) )
fi fi
} }
@ -1272,7 +1272,8 @@ _rpm_groups()
local IFS=$'\t' local IFS=$'\t'
# remove trailing backslash, or grep will complain # remove trailing backslash, or grep will complain
cur=${cur%"\\"} cur=${cur%"\\"}
COMPREPLY=( $( rpm -qa --queryformat '%{group}\n' | grep "^$cur" ) ) COMPREPLY=( $( rpm -qa $options --queryformat '%{group}\n' | \
grep "^$cur" ) )
# backslash escape spaces and translate newlines to tabs # backslash escape spaces and translate newlines to tabs
COMPREPLY=( $( echo ${COMPREPLY[@]} | sed 's/ /\\ /g' | tr '\n' '\t' ) ) COMPREPLY=( $( echo ${COMPREPLY[@]} | sed 's/ /\\ /g' | tr '\n' '\t' ) )
} }
@ -1281,11 +1282,20 @@ _rpm_groups()
# #
_rpm() _rpm()
{ {
local cur prev local cur prev ver options
COMPREPLY=() COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]} cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]} prev=${COMP_WORDS[COMP_CWORD-1]}
options=""
ver=$(rpm --version); ver=${ver##* }
if [[ "$ver" > "4.0.2" ]]; then
options="--nodigest"
fi
if [[ "$ver" > "4.0.99" ]]; then
options="$options --nosignature"
fi
if [ $COMP_CWORD -eq 1 ]; then if [ $COMP_CWORD -eq 1 ]; then
# first parameter on line # first parameter on line
@ -1344,15 +1354,15 @@ _rpm()
_filedir _filedir
else else
# complete on capabilities # complete on capabilities
COMPREPLY=( $( rpm -qa --queryformat \ COMPREPLY=( $( rpm -qa $options --queryformat \
'%{providename}\n' | grep "^$cur" ) ) '%{providename}\n' | grep "^$cur" ) )
fi fi
return 0 return 0
;; ;;
--whatrequires) --whatrequires)
# complete on capabilities # complete on capabilities
COMPREPLY=( $( rpm -qa --queryformat '%{requirename}\n' | \ COMPREPLY=( $( rpm -qa $options --queryformat \
grep "^$cur" ) ) '%{requirename}\n' | grep "^$cur" ) )
return 0 return 0
;; ;;
esac esac