@@ -104,15 +104,21 @@ complete -b builtin
104
104
# start of section containing completion functions called by other functions
105
105
106
106
# This function checks whether we have a given program on the system.
107
- # No need for bulky functions in memory if we don't.
108
107
#
109
- have ()
108
+ _have ()
110
109
{
111
- unset -v have
112
110
# Completions for system administrator commands are installed as well in
113
111
# 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
116
122
}
117
123
118
124
# This function checks whether a given readline variable
@@ -1691,15 +1697,12 @@ _longopt()
1691
1697
fi
1692
1698
}
1693
1699
# 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 \
1695
1701
cut date df diff dir du enscript env expand fmt fold gperf \
1696
1702
grep grub head indent irb ld ldd less ln ls m4 md5sum mkdir mkfifo mknod \
1697
1703
mv netstat nl nm objcopy objdump od paste patch pr ptx readelf rm rmdir \
1698
1704
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
1703
1706
1704
1707
declare -A _xspecs
1705
1708
_filedir_xspec ()
@@ -1810,7 +1813,27 @@ _install_xspec '!@(*.@(ks|jks|jceks|p12|pfx|bks|ubr|gkr|cer|crt|cert|p7b|pkipath
1810
1813
_install_xspec ' !*.@(mp[234c]|og[ag]|@(fl|a)ac|m4[abp]|spx|tta|w?(a)v|wma|aif?(f)|asf|ape)' kid3 kid3-qt
1811
1814
unset -f _install_xspec
1812
1815
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
1814
1837
if [[ -d $BASH_COMPLETION_COMPAT_DIR && -r $BASH_COMPLETION_COMPAT_DIR && \
1815
1838
-x $BASH_COMPLETION_COMPAT_DIR ]]; then
1816
1839
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 && \
1819
1842
&& -f $i && -r $i ]] && . " $i "
1820
1843
done
1821
1844
fi
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
1831
1845
unset i
1832
1846
1833
1847
# source user completion file
0 commit comments