Skip to content

Commit

Permalink
Load completions in separate files dynamically, get rid of have().
Browse files Browse the repository at this point in the history
  • Loading branch information
scop committed Oct 11, 2011
1 parent a6c9c61 commit 20c05b4
Show file tree
Hide file tree
Showing 210 changed files with 57 additions and 544 deletions.
54 changes: 34 additions & 20 deletions bash_completion
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,21 @@ complete -b builtin
# start of section containing completion functions called by other functions

# This function checks whether we have a given program on the system.
# No need for bulky functions in memory if we don't.
#
have()
_have()
{
unset -v have
# Completions for system administrator commands are installed as well in
# case completion is attempted via `sudo command ...'.
PATH=$PATH:/usr/sbin:/sbin:/usr/local/sbin type $1 &>/dev/null &&
have="yes"
PATH=$PATH:/usr/sbin:/sbin:/usr/local/sbin type $1 &>/dev/null
}

# Backwards compatibility for compat completions that use have().
# @deprecated should no longer be used; generally not needed with dynamically
# loaded completions, and _have is suitable for runtime use.
have()
{
unset -v have
_have $1 && have=yes
}

# This function checks whether a given readline variable
Expand Down Expand Up @@ -1691,15 +1697,12 @@ _longopt()
fi
}
# makeinfo and texi2dvi are defined elsewhere.
for i in a2ps awk base64 bash bc bison cat colordiff cp csplit \
complete -F _longopt a2ps awk base64 bash bc bison cat colordiff cp csplit \
cut date df diff dir du enscript env expand fmt fold gperf \
grep grub head indent irb ld ldd less ln ls m4 md5sum mkdir mkfifo mknod \
mv netstat nl nm objcopy objdump od paste patch pr ptx readelf rm rmdir \
sed seq sha{,1,224,256,384,512}sum shar sort split strip sum tac tail tee \
texindex touch tr uname unexpand uniq units vdir wc wget who; do
have $i && complete -F _longopt $i
done
unset i
texindex touch tr uname unexpand uniq units vdir wc wget who

declare -A _xspecs
_filedir_xspec()
Expand Down Expand Up @@ -1810,7 +1813,27 @@ _install_xspec '!@(*.@(ks|jks|jceks|p12|pfx|bks|ubr|gkr|cer|crt|cert|p7b|pkipath
_install_xspec '!*.@(mp[234c]|og[ag]|@(fl|a)ac|m4[abp]|spx|tta|w?(a)v|wma|aif?(f)|asf|ape)' kid3 kid3-qt
unset -f _install_xspec

# source completion directory definitions
# set up dynamic completion loading
_completion_loader()
{
local compdir="${BASH_SOURCE[0]%/*}/completions"

# If full path below completions dir exists, use it.
if [[ $1 == */* && -f "$compdir/$1" ]]; then
. "$compdir/$1" &>/dev/null && return 124 || return 1
fi

# Special case for init.d scripts.
if [[ $1 == /etc?(/rc.d)/init.d/* ]]; then
. "$compdir/service" &>/dev/null && return 124 || return 1
fi

# Finally, use basename.
. "$compdir/${1##*/}" &>/dev/null && return 124
} &&
complete -D -F _completion_loader

# source compat completion directory definitions
if [[ -d $BASH_COMPLETION_COMPAT_DIR && -r $BASH_COMPLETION_COMPAT_DIR && \
-x $BASH_COMPLETION_COMPAT_DIR ]]; then
for i in $(LC_ALL=C command ls "$BASH_COMPLETION_COMPAT_DIR"); do
Expand All @@ -1819,15 +1842,6 @@ if [[ -d $BASH_COMPLETION_COMPAT_DIR && -r $BASH_COMPLETION_COMPAT_DIR && \
&& -f $i && -r $i ]] && . "$i"
done
fi
if [[ "${BASH_SOURCE[0]%/*}/completions" != $BASH_COMPLETION_COMPAT_DIR && \
-d "${BASH_SOURCE[0]%/*}/completions" && -r "${BASH_SOURCE[0]%/*}/completions" && \
-x "${BASH_SOURCE[0]%/*}/completions" ]]; then
for i in $(LC_ALL=C command ls "${BASH_SOURCE[0]%/*}/completions"); do
i="${BASH_SOURCE[0]%/*}/completions/$i"
[[ ${i##*/} != @($_backup_glob|Makefile*|$_blacklist_glob) \
&& -f $i && -r $i ]] && . "$i"
done
fi
unset i

# source user completion file
Expand Down
2 changes: 0 additions & 2 deletions completions/_mock
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

# bash completion for mock

have mock || return

_mock()
{
local cur prev words cword split
Expand Down
2 changes: 1 addition & 1 deletion completions/_modules
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

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

_module_list ()
{
Expand Down
2 changes: 0 additions & 2 deletions completions/_subversion
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

# svn completion

have svn || return

_svn()
{
local cur prev words cword
Expand Down
2 changes: 0 additions & 2 deletions completions/_yum
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

# yum(8) completion

have yum || return

_yum_list()
{
if [[ "$1" == all ]] ; then
Expand Down
2 changes: 0 additions & 2 deletions completions/_yum-utils
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

# bash completion for repomanage

have repomanage || return

_repomanage()
{
local cur prev words cword split
Expand Down
2 changes: 0 additions & 2 deletions completions/abook
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# abook(1) completion

have abook || return

_abook()
{
local cur prev words cword
Expand Down
8 changes: 3 additions & 5 deletions completions/ant
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# bash completion for ant and phing

have ant || have phing || return

_ant()
{
local cur prev words cword
Expand Down Expand Up @@ -59,9 +57,9 @@ _ant()
COMPREPLY=( $( compgen -W '$targets' -- "$cur" ) )
fi
} &&
have ant && { type complete-ant-cmd.pl &>/dev/null && \
complete -C complete-ant-cmd.pl -F _ant ant || complete -F _ant ant; }
have phing && complete -F _ant phing
complete -F _ant ant phing
type complete-ant-cmd.pl &>/dev/null && \
complete -C complete-ant-cmd.pl -F _ant ant

# Local variables:
# mode: shell-script
Expand Down
2 changes: 0 additions & 2 deletions completions/apache2ctl
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# apache2ctl(1) completion

have apache2ctl || return

_apache2ctl()
{
local cur prev words cword
Expand Down
2 changes: 0 additions & 2 deletions completions/apt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Debian apt-get(8) completion.

have apt-get &&
_apt_get()
{
local cur prev words cword
Expand Down Expand Up @@ -75,7 +74,6 @@ complete -F _apt_get apt-get

# Debian apt-cache(8) completion.
#
have apt-cache &&
_apt_cache()
{
local cur prev words cword
Expand Down
2 changes: 0 additions & 2 deletions completions/apt-build
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# Debian apt-build(1) completion.

have apt-build || return

_apt_build()
{
local cur prev words cword
Expand Down
4 changes: 1 addition & 3 deletions completions/aptitude
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Debian aptitude(1) completion

have aptitude || return

have grep-status && {
_have grep-status && {
_comp_dpkg_hold_packages()
{
grep-status -P -e "^$1" -a -FStatus 'hold' -n -s Package
Expand Down
2 changes: 0 additions & 2 deletions completions/asciidoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
have asciidoc || have a2x || return

_asciidoc_doctype()
{
COMPREPLY+=( $( compgen -W 'article book manpage' -- "$cur" ) )
Expand Down
2 changes: 0 additions & 2 deletions completions/aspell
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# bash completion for aspell

have aspell || return

_aspell_dictionary()
{
local datadir
Expand Down
3 changes: 0 additions & 3 deletions completions/autoconf
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Completions for autoconf tools

have autoconf &&
_autoconf()
{
local cur prev words cword split
Expand Down Expand Up @@ -38,7 +37,6 @@ _autoconf()
} &&
complete -F _autoconf autoconf

have autoreconf || have autoheader &&
_autoreconf()
{
local cur prev words cword split
Expand Down Expand Up @@ -77,7 +75,6 @@ _autoreconf()
} &&
complete -F _autoreconf autoreconf autoheader

have autoscan || have autoupdate &&
_autoscan()
{
local cur prev words cword split
Expand Down
2 changes: 0 additions & 2 deletions completions/automake
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Completions for automake tools

have automake &&
_automake()
{
local cur prev words cword split
Expand Down Expand Up @@ -34,7 +33,6 @@ _automake()
} &&
complete -F _automake automake automake-1.11

have aclocal &&
_aclocal()
{
local cur prev words cword split
Expand Down
2 changes: 0 additions & 2 deletions completions/autorpm
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# autorpm(8) completion

have autorpm || return

_autorpm()
{
local cur prev words cword
Expand Down
2 changes: 0 additions & 2 deletions completions/bind-utils
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# bash completion for nslookup

have nslookup || have host || return

_bind_queryclass()
{
COMPREPLY+=( $( compgen -W 'IN CH HS ANY' -- "$cur" ) )
Expand Down
2 changes: 0 additions & 2 deletions completions/bitkeeper
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# BitKeeper completion adapted from code by Bart Trojanowski <bart@jukie.net>

have bk || return

_bk()
{
local cur prev words cword
Expand Down
3 changes: 0 additions & 3 deletions completions/bittorrent
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# btdownloadheadless(1) completion

have btdownloadheadless.py || have btdownloadcurses.py || \
have btdownloadgui.py || return

_btdownload()
{
local cur prev words cword
Expand Down
2 changes: 0 additions & 2 deletions completions/bluez
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# bash completion for bluez utils

have hcitool || return

_bluetooth_adresses()
{
if [ -n "${COMP_BLUETOOTH_SCAN:-}" ]; then
Expand Down
2 changes: 0 additions & 2 deletions completions/brctl
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# bash completion for brctl

have brctl || return

_brctl()
{
local cur prev words cword
Expand Down
2 changes: 0 additions & 2 deletions completions/bzip2
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# bash completion for bzip2

have bzip2 || have pbzip2 || have lbzip2 || return

_bzip2()
{
local cur prev words cword
Expand Down
2 changes: 0 additions & 2 deletions completions/cal
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
have cal || have ncal || return

_cal()
{
local cur prev words cword
Expand Down
2 changes: 0 additions & 2 deletions completions/cardctl
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# Linux cardctl(8) completion

have cardctl || have pccardctl || return

_cardctl()
{
local cur prev words cword
Expand Down
2 changes: 0 additions & 2 deletions completions/cfengine
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# bash completion for cfengine

have cfagent || return

_cfagent()
{
local cur prev words cword
Expand Down
2 changes: 0 additions & 2 deletions completions/chkconfig
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# chkconfig(8) completion

have chkconfig || return

_chkconfig()
{
local cur prev words cword split
Expand Down
2 changes: 0 additions & 2 deletions completions/chrpath
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
have chrpath || return

_chrpath()
{
local cur prev words cword
Expand Down
2 changes: 0 additions & 2 deletions completions/chsh
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# chsh(1) completion

have chsh || return

_chsh()
{
local cur prev words cword
Expand Down
2 changes: 0 additions & 2 deletions completions/cksfv
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# cksfv completion by Chris <xris@forevermore.net>

have cksfv || return

_cksfv()
{
local cur prev words cword
Expand Down
2 changes: 0 additions & 2 deletions completions/clisp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# bash brogrammable completion for various Common Lisp implementations by
# Nikodemus Siivola <nikodemus@random-state.net>

have clisp || return

_clisp()
{
local cur prev words cword
Expand Down
2 changes: 0 additions & 2 deletions completions/configure
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# bash completion for configure

# No "have configure" here on purpose, it's rarely in any $PATH

_configure()
{
local cur prev words cword split
Expand Down
Loading

0 comments on commit 20c05b4

Please sign in to comment.