Skip to content

Commit 20c05b4

Browse files
committed
Load completions in separate files dynamically, get rid of have().
1 parent a6c9c61 commit 20c05b4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

210 files changed

+57
-544
lines changed

bash_completion

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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

17041707
declare -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
18111814
unset -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
18141837
if [[ -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
18211844
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
18311845
unset i
18321846

18331847
# source user completion file

completions/_mock

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
# bash completion for mock
55

6-
have mock || return
7-
86
_mock()
97
{
108
local cur prev words cword split

completions/_modules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
# Test for existence of /etc/profile.d/modules.sh too because we may end up
2121
# being sourced before it and thus before the `module' alias has been defined.
22-
[ -f /etc/profile.d/modules.sh ] || have module || return
22+
[ -f /etc/profile.d/modules.sh ] || return 1
2323

2424
_module_list ()
2525
{

completions/_subversion

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
# svn completion
55

6-
have svn || return
7-
86
_svn()
97
{
108
local cur prev words cword

completions/_yum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
# yum(8) completion
55

6-
have yum || return
7-
86
_yum_list()
97
{
108
if [[ "$1" == all ]] ; then

completions/_yum-utils

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
# bash completion for repomanage
55

6-
have repomanage || return
7-
86
_repomanage()
97
{
108
local cur prev words cword split

completions/abook

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# abook(1) completion
22

3-
have abook || return
4-
53
_abook()
64
{
75
local cur prev words cword

completions/ant

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# bash completion for ant and phing
22

3-
have ant || have phing || return
4-
53
_ant()
64
{
75
local cur prev words cword
@@ -59,9 +57,9 @@ _ant()
5957
COMPREPLY=( $( compgen -W '$targets' -- "$cur" ) )
6058
fi
6159
} &&
62-
have ant && { type complete-ant-cmd.pl &>/dev/null && \
63-
complete -C complete-ant-cmd.pl -F _ant ant || complete -F _ant ant; }
64-
have phing && complete -F _ant phing
60+
complete -F _ant ant phing
61+
type complete-ant-cmd.pl &>/dev/null && \
62+
complete -C complete-ant-cmd.pl -F _ant ant
6563

6664
# Local variables:
6765
# mode: shell-script

completions/apache2ctl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# apache2ctl(1) completion
22

3-
have apache2ctl || return
4-
53
_apache2ctl()
64
{
75
local cur prev words cword

completions/apt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Debian apt-get(8) completion.
22

3-
have apt-get &&
43
_apt_get()
54
{
65
local cur prev words cword
@@ -75,7 +74,6 @@ complete -F _apt_get apt-get
7574

7675
# Debian apt-cache(8) completion.
7776
#
78-
have apt-cache &&
7977
_apt_cache()
8078
{
8179
local cur prev words cword

0 commit comments

Comments
 (0)