Split rpm and rpmbuild completions and improve them both.

The option sets are different, and rpm should not have been used to
build packages since rpm 4.0, and could not have been used for that
since rpm 4.1.
This commit is contained in:
Ville Skyttä 2011-02-10 23:51:26 +02:00
parent 4c1e0d5cf2
commit 6042cbe2f5
4 changed files with 116 additions and 70 deletions

View File

@ -4,6 +4,7 @@ bash-completion (2.x)
* Improve gendiff completion. * Improve gendiff completion.
* Try harder to find the correct perl executable to run the perl helper with. * Try harder to find the correct perl executable to run the perl helper with.
* Drop rpm query support for rpm < 4.1. * Drop rpm query support for rpm < 4.1.
* Split rpm and rpmbuild completions and improve them both.
-- David Paleino <d.paleino@gmail.com> Sun, 06 Feb 2011 21:46:37 +0100 -- David Paleino <d.paleino@gmail.com> Sun, 06 Feb 2011 21:46:37 +0100

View File

@ -15,7 +15,7 @@ _rpm_installed_packages()
# SUSE's rpmqpack is faster than rpm -qa # SUSE's rpmqpack is faster than rpm -qa
COMPREPLY=( $( compgen -W '$( rpmqpack )' -- "$cur" ) ) COMPREPLY=( $( compgen -W '$( rpmqpack )' -- "$cur" ) )
else else
COMPREPLY=( $( rpm -qa --nodigest --nosignature \ COMPREPLY=( $( ${1:-rpm} -qa --nodigest --nosignature \
--queryformat='%{NAME} ' "$cur*" 2>/dev/null ) ) --queryformat='%{NAME} ' "$cur*" 2>/dev/null ) )
fi fi
} }
@ -23,10 +23,18 @@ _rpm_installed_packages()
_rpm_groups() _rpm_groups()
{ {
local IFS=$'\n' local IFS=$'\n'
COMPREPLY=( $( compgen -W "$( rpm -qa --nodigest --nosignature \ COMPREPLY=( $( compgen -W "$( ${1:-rpm} -qa --nodigest --nosignature \
--queryformat='%{GROUP}\n' 2>/dev/null )" -- "$cur" ) ) --queryformat='%{GROUP}\n' 2>/dev/null )" -- "$cur" ) )
} }
_rpm_macros()
{
# get a list of macros
COMPREPLY=( $( compgen -W "$( ${1:-rpm} --showrc | sed -ne \
's/^-\{0,1\}[0-9]\{1,\}[:=][[:space:]]\{1,\}\([^[:space:](]\{3,\}\).*/%\1/p' )" \
-- "$cur" ) )
}
# rpm(8) completion # rpm(8) completion
# #
_rpm() _rpm()
@ -39,24 +47,15 @@ _rpm()
if [ $COMP_CWORD -eq 1 ]; then if [ $COMP_CWORD -eq 1 ]; then
# first parameter on line # first parameter on line
case $cur in case $cur in
-b*)
COMPREPLY=( $( compgen -W '-ba -bb -bc -bi -bl -bp -bs' \
-- "$cur" ) )
;;
-t*)
COMPREPLY=( $( compgen -W '-ta -tb -tc -ti -tl -tp -ts' \
-- "$cur" ) )
;;
--*) --*)
COMPREPLY=( $( compgen -W '--help --version --initdb \ COMPREPLY=( $( compgen -W '--help --version --initdb \
--checksig --recompile --rebuild --resign --addsign \ --checksig --resign --addsign --rebuilddb --showrc \
--rebuilddb --showrc --setperms --setugids --tarbuild \ --setperms --setugids --eval --install --upgrade --query \
--eval --install --upgrade --query --freshen --erase \ --freshen --erase --verify --querytags --import' \
--verify --querytags --rmsource --rmspec --clean \ -- "$cur" ) )
--import' -- "$cur" ) )
;; ;;
*) *)
COMPREPLY=( $( compgen -W '-b -e -E -F -i -q -t -U -V' \ COMPREPLY=( $( compgen -W '-e -E -F -i -q -t -U -V' \
-- "$cur" ) ) -- "$cur" ) )
;; ;;
esac esac
@ -70,10 +69,7 @@ _rpm()
return 0 return 0
;; ;;
--eval|-E) --eval|-E)
# get a list of macros _rpm_macros $1
COMPREPLY=( $( compgen -W "$( rpm --showrc | sed -ne \
's/^-\{0,1\}[0-9]\{1,\}[:=][[:space:]]\{1,\}\([^[:space:](]\{3,\}\).*/%\1/p' )" \
-- "$cur" ) )
return 0 return 0
;; ;;
--pipe) --pipe)
@ -96,9 +92,9 @@ _rpm()
else else
# complete on capabilities # complete on capabilities
local IFS=$'\n' local IFS=$'\n'
COMPREPLY=( $( compgen -W "$( rpm -qa --nodigest \ COMPREPLY=( $( compgen -W "$( $1 -qa --nodigest --nosignature \
--nosignature --queryformat='%{PROVIDENAME}\n' \ --queryformat='%{PROVIDENAME}\n' 2>/dev/null )" \
2>/dev/null )" -- "$cur" ) ) -- "$cur" ) )
fi fi
return 0 return 0
;; ;;
@ -108,16 +104,10 @@ _rpm()
else else
# complete on capabilities # complete on capabilities
local IFS=$'\n' local IFS=$'\n'
COMPREPLY=( $( compgen -W "$( rpm -qa --nodigest \ COMPREPLY=( $( compgen -W "$( $1 -qa --nodigest --nosignature \
--nosignature --queryformat='%{REQUIRENAME}\n' \ --queryformat='%{REQUIRENAME}\n' 2>/dev/null )" \
2>/dev/null )" -- "$cur" ) )
fi
return 0
;;
--target)
COMPREPLY=( $( compgen -W "$( command rpm --showrc | sed -ne \
's/^\s*compatible\s\s*build\s\s*archs\s*:\s*\(.*\)/\1/ p' )" \
-- "$cur" ) ) -- "$cur" ) )
fi
return 0 return 0
;; ;;
--define|-D|--fileid|--hdrid|--pkgid) --define|-D|--fileid|--hdrid|--pkgid)
@ -151,7 +141,7 @@ _rpm()
--noscripts --notriggers --nodeps --test --repackage" \ --noscripts --notriggers --nodeps --test --repackage" \
-- "$cur" ) ) -- "$cur" ) )
else else
_rpm_installed_packages _rpm_installed_packages $1
fi fi
;; ;;
-q*|--query) -q*|--query)
@ -172,7 +162,7 @@ _rpm()
fi fi
elif [[ $COMP_LINE == *\ -@(*([^ -])g|-group )* ]]; then elif [[ $COMP_LINE == *\ -@(*([^ -])g|-group )* ]]; then
# -qg completion # -qg completion
_rpm_groups _rpm_groups $1
elif [[ $COMP_LINE == *\ -@(*([^ -])p|-package )* ]]; then elif [[ $COMP_LINE == *\ -@(*([^ -])p|-package )* ]]; then
# -qp; uninstalled package completion # -qp; uninstalled package completion
if [[ "$cur" == -* ]]; then if [[ "$cur" == -* ]]; then
@ -190,7 +180,7 @@ _rpm()
--triggeredby --whatprovides --whatrequires" \ --triggeredby --whatprovides --whatrequires" \
-- "$cur" ) ) -- "$cur" ) )
elif [[ $COMP_LINE != *\ -@(*([^ -])a|-all )* ]]; then elif [[ $COMP_LINE != *\ -@(*([^ -])a|-all )* ]]; then
_rpm_installed_packages _rpm_installed_packages $1
fi fi
fi fi
;; ;;
@ -212,48 +202,18 @@ _rpm()
elif [[ $COMP_LINE == *\ -@(*([^ -])f|-file )* ]]; then elif [[ $COMP_LINE == *\ -@(*([^ -])f|-file )* ]]; then
_filedir _filedir
elif [[ $COMP_LINE == *\ -@(*([^ -])g|-group )* ]]; then elif [[ $COMP_LINE == *\ -@(*([^ -])g|-group )* ]]; then
_rpm_groups _rpm_groups $1
elif [[ $COMP_LINE == *\ -@(*([^ -])p|-package )* ]]; then elif [[ $COMP_LINE == *\ -@(*([^ -])p|-package )* ]]; then
_filedir '[rs]pm' _filedir '[rs]pm'
else else
_rpm_installed_packages _rpm_installed_packages $1
fi fi
;; ;;
-[bt]*)
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W "$opts --short-circuit --timecheck \
--clean --rmsource --rmspec --test --sign --buildroot \
--target --nobuild --nodeps --nodirtokens" -- "$cur" ) )
elif [[ ${COMP_WORDS[1]} == -b* ]]; then
_filedir spec
else
_filedir '@(t?(ar.)@([gx]z|bz?(2))|tar?(.@(lzma|Z)))'
fi
;;
--rebuild|--recompile)
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W "$opts --nodeps --rmsource \
--rmspec --sign --nodirtokens --target" -- "$cur" ) )
else
_filedir '@(?(no)src.r|s)pm'
fi
;;
--tarbuild)
_filedir '@(t?(ar.)@([gx]z|bz?(2))|tar?(.@(lzma|Z)))'
;;
--resign|--addsign) --resign|--addsign)
_filedir '[rs]pm' _filedir '[rs]pm'
;; ;;
--setperms|--setgids) --setperms|--setgids)
_rpm_installed_packages _rpm_installed_packages $1
;;
--clean|--rmsource|--rmspec)
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '--clean --rmsource --rmspec' \
-- "$cur" ) )
else
_filedir spec
fi
;; ;;
--import|--dbpath|--root) --import|--dbpath|--root)
if [[ "$cur" == -* ]]; then if [[ "$cur" == -* ]]; then
@ -266,8 +226,72 @@ _rpm()
esac esac
return 0 return 0
} } &&
complete -F _rpm rpm rpmbuild complete -F _rpm rpm
_rpmbuild()
{
COMPREPLY=()
local cur prev words split=false
_get_comp_words_by_ref cur prev words
_split_longopt && split=true
local rpm="${1%build*}"
[[ $rpm == $1 ]] || ! type $rpm &>/dev/null && rpm=
case $prev in
--buildroot|--root|-r|--dbpath)
_filedir -d
return 0
;;
--target)
COMPREPLY=( $( compgen -W "$( $rpm --showrc | sed -ne \
's/^\s*compatible\s\s*build\s\s*archs\s*:\s*\(.*\)/\1/ p' )" \
-- "$cur" ) )
return 0
;;
--eval|-E)
_rpm_macros $rpm
return 0
;;
--macros|--rcfile)
_filedir
return 0
;;
--define|-D|--with|--without|--buildpolicy)
return 0
;;
esac
$split && return 0
if [[ $cur == -* ]]; then
COMPREPLY=( $( compgen -W "$( _parse_help "$1" )" -- "$cur" ) )
return 0
fi
# Figure out file extensions to complete
local word ext
for word in ${words[@]}; do
case $word in
-b?)
ext=spec
break
;;
-t?|--tarbuild)
ext='@(t?(ar.)@([gx]z|bz?(2))|tar?(.@(lzma|Z)))'
break
;;
--rebuild|--recompile)
ext='@(?(no)src.r|s)pm'
break
;;
esac
done
[[ -n $ext ]] && _filedir $ext
} &&
complete -F _rpmbuild rpmbuild rpmbuild-md5
} }
have gendiff && have gendiff &&

View File

@ -0,0 +1 @@
assert_source_completions rpmbuild

View File

@ -0,0 +1,20 @@
proc setup {} {
save_env
}
proc teardown {} {
assert_env_unmodified
}
setup
assert_complete_any "rpmbuild -"
sync_after_int
teardown