@@ -104,15 +104,21 @@ complete -b builtin
104104# start of section containing completion functions called by other functions
105105
106106# This function checks whether we have a given program on the system.
107- # No need for bulky functions in memory if we don't.
108107#
109- have ()
108+ _have ()
110109{
111- unset -v have
112110 # Completions for system administrator commands are installed as well in
113111 # case completion is attempted via `sudo command ...'.
114- PATH=$PATH :/usr/sbin:/sbin:/usr/local/sbin type $1 & > /dev/null &&
115- have=" yes"
112+ PATH=$PATH :/usr/sbin:/sbin:/usr/local/sbin type $1 & > /dev/null
113+ }
114+
115+ # Backwards compatibility for compat completions that use have().
116+ # @deprecated should no longer be used; generally not needed with dynamically
117+ # loaded completions, and _have is suitable for runtime use.
118+ have ()
119+ {
120+ unset -v have
121+ _have $1 && have=yes
116122}
117123
118124# This function checks whether a given readline variable
@@ -1691,15 +1697,12 @@ _longopt()
16911697 fi
16921698}
16931699# makeinfo and texi2dvi are defined elsewhere.
1694- for i in a2ps awk base64 bash bc bison cat colordiff cp csplit \
1700+ complete -F _longopt a2ps awk base64 bash bc bison cat colordiff cp csplit \
16951701 cut date df diff dir du enscript env expand fmt fold gperf \
16961702 grep grub head indent irb ld ldd less ln ls m4 md5sum mkdir mkfifo mknod \
16971703 mv netstat nl nm objcopy objdump od paste patch pr ptx readelf rm rmdir \
16981704 sed seq sha{,1,224,256,384,512}sum shar sort split strip sum tac tail tee \
1699- texindex touch tr uname unexpand uniq units vdir wc wget who; do
1700- have $i && complete -F _longopt $i
1701- done
1702- unset i
1705+ texindex touch tr uname unexpand uniq units vdir wc wget who
17031706
17041707declare -A _xspecs
17051708_filedir_xspec ()
@@ -1810,7 +1813,27 @@ _install_xspec '!@(*.@(ks|jks|jceks|p12|pfx|bks|ubr|gkr|cer|crt|cert|p7b|pkipath
18101813_install_xspec ' !*.@(mp[234c]|og[ag]|@(fl|a)ac|m4[abp]|spx|tta|w?(a)v|wma|aif?(f)|asf|ape)' kid3 kid3-qt
18111814unset -f _install_xspec
18121815
1813- # source completion directory definitions
1816+ # set up dynamic completion loading
1817+ _completion_loader ()
1818+ {
1819+ local compdir=" ${BASH_SOURCE[0]%/* } /completions"
1820+
1821+ # If full path below completions dir exists, use it.
1822+ if [[ $1 == * /* && -f " $compdir /$1 " ]]; then
1823+ . " $compdir /$1 " & > /dev/null && return 124 || return 1
1824+ fi
1825+
1826+ # Special case for init.d scripts.
1827+ if [[ $1 == /etc? (/rc.d)/init.d/* ]]; then
1828+ . " $compdir /service" & > /dev/null && return 124 || return 1
1829+ fi
1830+
1831+ # Finally, use basename.
1832+ . " $compdir /${1##*/ } " & > /dev/null && return 124
1833+ } &&
1834+ complete -D -F _completion_loader
1835+
1836+ # source compat completion directory definitions
18141837if [[ -d $BASH_COMPLETION_COMPAT_DIR && -r $BASH_COMPLETION_COMPAT_DIR && \
18151838 -x $BASH_COMPLETION_COMPAT_DIR ]]; then
18161839 for i in $( LC_ALL=C command ls " $BASH_COMPLETION_COMPAT_DIR " ) ; do
@@ -1819,15 +1842,6 @@ if [[ -d $BASH_COMPLETION_COMPAT_DIR && -r $BASH_COMPLETION_COMPAT_DIR && \
18191842 && -f $i && -r $i ]] && . " $i "
18201843 done
18211844fi
1822- if [[ " ${BASH_SOURCE[0]%/* } /completions" != $BASH_COMPLETION_COMPAT_DIR && \
1823- -d " ${BASH_SOURCE[0]%/* } /completions" && -r " ${BASH_SOURCE[0]%/* } /completions" && \
1824- -x " ${BASH_SOURCE[0]%/* } /completions" ]]; then
1825- for i in $( LC_ALL=C command ls " ${BASH_SOURCE[0]%/* } /completions" ) ; do
1826- i=" ${BASH_SOURCE[0]%/* } /completions/$i "
1827- [[ ${i##*/ } != @ ($_backup_glob | Makefile* | $_blacklist_glob ) \
1828- && -f $i && -r $i ]] && . " $i "
1829- done
1830- fi
18311845unset i
18321846
18331847# source user completion file
0 commit comments