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

completions/apt-build

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

3-
have apt-build || return
4-
53
_apt_build()
64
{
75
local cur prev words cword

completions/aptitude

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# Debian aptitude(1) completion
22

3-
have aptitude || return
4-
5-
have grep-status && {
3+
_have grep-status && {
64
_comp_dpkg_hold_packages()
75
{
86
grep-status -P -e "^$1" -a -FStatus 'hold' -n -s Package

completions/asciidoc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
have asciidoc || have a2x || return
2-
31
_asciidoc_doctype()
42
{
53
COMPREPLY+=( $( compgen -W 'article book manpage' -- "$cur" ) )

completions/aspell

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

3-
have aspell || return
4-
53
_aspell_dictionary()
64
{
75
local datadir

completions/autoconf

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Completions for autoconf tools
22

3-
have autoconf &&
43
_autoconf()
54
{
65
local cur prev words cword split
@@ -38,7 +37,6 @@ _autoconf()
3837
} &&
3938
complete -F _autoconf autoconf
4039

41-
have autoreconf || have autoheader &&
4240
_autoreconf()
4341
{
4442
local cur prev words cword split
@@ -77,7 +75,6 @@ _autoreconf()
7775
} &&
7876
complete -F _autoreconf autoreconf autoheader
7977

80-
have autoscan || have autoupdate &&
8178
_autoscan()
8279
{
8380
local cur prev words cword split

completions/automake

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Completions for automake tools
22

3-
have automake &&
43
_automake()
54
{
65
local cur prev words cword split
@@ -34,7 +33,6 @@ _automake()
3433
} &&
3534
complete -F _automake automake automake-1.11
3635

37-
have aclocal &&
3836
_aclocal()
3937
{
4038
local cur prev words cword split

completions/autorpm

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

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

completions/bind-utils

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

3-
have nslookup || have host || return
4-
53
_bind_queryclass()
64
{
75
COMPREPLY+=( $( compgen -W 'IN CH HS ANY' -- "$cur" ) )

completions/bitkeeper

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# BitKeeper completion adapted from code by Bart Trojanowski <[email protected]>
22

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

completions/bittorrent

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

3-
have btdownloadheadless.py || have btdownloadcurses.py || \
4-
have btdownloadgui.py || return
5-
63
_btdownload()
74
{
85
local cur prev words cword

completions/bluez

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# bash completion for bluez utils
22

3-
have hcitool || return
4-
53
_bluetooth_adresses()
64
{
75
if [ -n "${COMP_BLUETOOTH_SCAN:-}" ]; then

completions/brctl

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

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

completions/bzip2

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

3-
have bzip2 || have pbzip2 || have lbzip2 || return
4-
53
_bzip2()
64
{
75
local cur prev words cword

completions/cal

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
have cal || have ncal || return
2-
31
_cal()
42
{
53
local cur prev words cword

completions/cardctl

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

3-
have cardctl || have pccardctl || return
4-
53
_cardctl()
64
{
75
local cur prev words cword

completions/cfengine

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

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

completions/chkconfig

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

3-
have chkconfig || return
4-
53
_chkconfig()
64
{
75
local cur prev words cword split

completions/chrpath

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
have chrpath || return
2-
31
_chrpath()
42
{
53
local cur prev words cword

completions/chsh

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

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

completions/cksfv

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# cksfv completion by Chris <[email protected]>
22

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

completions/clisp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# bash brogrammable completion for various Common Lisp implementations by
22
# Nikodemus Siivola <[email protected]>
33

4-
have clisp || return
5-
64
_clisp()
75
{
86
local cur prev words cword

completions/configure

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

3-
# No "have configure" here on purpose, it's rarely in any $PATH
4-
53
_configure()
64
{
75
local cur prev words cword split

0 commit comments

Comments
 (0)