Get rid of $BASH_COMPLETION as well

This commit is contained in:
David Paleino 2011-05-02 19:01:33 +02:00
parent 88f9f46d81
commit 4632248cbb
8 changed files with 14 additions and 21 deletions

View File

@ -1,4 +1,4 @@
SUBDIRS = completions test SUBDIRS = completions helpers test
pkgdata_DATA = bash_completion pkgdata_DATA = bash_completion

7
README
View File

@ -38,11 +38,6 @@ if [ -f /sw/etc/bash_completion ]; then
. /sw/etc/bash_completion . /sw/etc/bash_completion
fi fi
If you are putting the bash completion source file somewhere other
than /etc/bash_completion, you should ensure that $BASH_COMPLETION is
set to point to it before you source it. Your ~/.bashrc file is a good
place to do this.
TROUBLESHOOTING TROUBLESHOOTING
--------------- ---------------
@ -125,7 +120,7 @@ Q. I author/maintain package X and would like to maintain my own
completion code for this package. Where should I put it to be sure completion code for this package. Where should I put it to be sure
that interactive bash shells will find it and source it? that interactive bash shells will find it and source it?
Put it in the directory pointed to by $BASH_COMPLETION_DIR, which Put it in the directory pointed to by $BASH_COMPLETION_COMPAT_DIR, which
is defined at the beginning of the main completion script. Any is defined at the beginning of the main completion script. Any
scripts placed in this directory will be sourced by interactive scripts placed in this directory will be sourced by interactive
bash shells. Usually, this is /etc/bash_completion.d. bash shells. Usually, this is /etc/bash_completion.d.

View File

@ -39,9 +39,8 @@ fi
# Alter the following to reflect the location of this file. # Alter the following to reflect the location of this file.
# #
[ -n "$BASH_COMPLETION" ] || BASH_COMPLETION=/usr/share/bash-completion/bash_completion
[ -n "$BASH_COMPLETION_COMPAT_DIR" ] || BASH_COMPLETION_COMPAT_DIR=/etc/bash_completion.d [ -n "$BASH_COMPLETION_COMPAT_DIR" ] || BASH_COMPLETION_COMPAT_DIR=/etc/bash_completion.d
readonly BASH_COMPLETION BASH_COMPLETION_COMPAT_DIR readonly BASH_COMPLETION_COMPAT_DIR
# Set a couple of useful vars # Set a couple of useful vars
# #
@ -1752,7 +1751,7 @@ _filedir_xspec()
local IFS=$'\n' xspec local IFS=$'\n' xspec
# get first exclusion compspec that matches this command # get first exclusion compspec that matches this command
xspec=$( awk "/^complete[ \t]+.*[ \t]${1##*/}([ \t]|\$)/ { print \$0; exit }" \ xspec=$( awk "/^complete[ \t]+.*[ \t]${1##*/}([ \t]|\$)/ { print \$0; exit }" \
"$BASH_COMPLETION" ) "${BASH_SOURCE[0]}" )
# prune to leave nothing but the -X spec # prune to leave nothing but the -X spec
xspec=${xspec#*-X } xspec=${xspec#*-X }
xspec=${xspec%% *} xspec=${xspec%% *}
@ -1790,7 +1789,7 @@ _filedir_xspec()
[ ${#toks[@]} -ne 0 ] && compopt -o filenames [ ${#toks[@]} -ne 0 ] && compopt -o filenames
COMPREPLY=( "${toks[@]}" ) COMPREPLY=( "${toks[@]}" )
} }
list=( $( sed -ne '/^# START exclude/,/^# FINISH exclude/p' "$BASH_COMPLETION" | \ list=( $( sed -ne '/^# START exclude/,/^# FINISH exclude/p' "${BASH_SOURCE[0]}" | \
# read exclusion compspecs # read exclusion compspecs
( (
while read line while read line
@ -1822,11 +1821,11 @@ if [[ -d $BASH_COMPLETION_COMPAT_DIR && -r $BASH_COMPLETION_COMPAT_DIR && \
&& -f $i && -r $i ]] && . "$i" && -f $i && -r $i ]] && . "$i"
done done
fi fi
if [[ "${BASH_COMPLETION%/*}/completions" != $BASH_COMPLETION_COMPAT_DIR && \ if [[ "${BASH_SOURCE[0]%/*}/completions" != $BASH_COMPLETION_COMPAT_DIR && \
-d "${BASH_COMPLETION%/*}/completions" && -r "${BASH_COMPLETION%/*}/completions" && \ -d "${BASH_SOURCE[0]%/*}/completions" && -r "${BASH_SOURCE[0]%/*}/completions" && \
-x "${BASH_COMPLETION%/*}/completions" ]]; then -x "${BASH_SOURCE[0]%/*}/completions" ]]; then
for i in $(LC_ALL=C command ls "${BASH_COMPLETION%/*}/completions"); do for i in $(LC_ALL=C command ls "${BASH_SOURCE[0]%/*}/completions"); do
i="${BASH_COMPLETION%/*}/completions/$i" i="${BASH_SOURCE[0]%/*}/completions/$i"
[[ ${i##*/} != @($_backup_glob|Makefile*) \ [[ ${i##*/} != @($_backup_glob|Makefile*) \
&& -f $i && -r $i ]] && . "$i" && -f $i && -r $i ]] && . "$i"
done done
@ -1834,7 +1833,7 @@ fi
unset i unset i
# source user completion file # source user completion file
[[ $BASH_COMPLETION != ~/.bash_completion && -r ~/.bash_completion ]] \ [[ ${BASH_SOURCE[0]} != ~/.bash_completion && -r ~/.bash_completion ]] \
&& . ~/.bash_completion && . ~/.bash_completion
unset -f have unset -f have
unset UNAME USERLAND have unset UNAME USERLAND have

View File

@ -1,5 +1,5 @@
# Check for interactive bash and that we haven't already been sourced. # Check for interactive bash and that we haven't already been sourced.
[ -z "$BASH_VERSION" -o -z "$PS1" -o -n "$BASH_COMPLETION" ] && return [ -z "$BASH_VERSION" -o -z "$PS1" -o -n "$BASH_COMPLETION_COMPAT_DIR" ] && return
# Check for recent enough version of bash. # Check for recent enough version of bash.
bash=${BASH_VERSION%.*}; bmajor=${bash%.*}; bminor=${bash#*.} bash=${BASH_VERSION%.*}; bmajor=${bash%.*}; bminor=${bash#*.}

View File

@ -1,4 +1,3 @@
SUBDIRS = helpers
bashcomp_DATA = abook \ bashcomp_DATA = abook \
ant \ ant \
apache2ctl \ apache2ctl \

View File

@ -5,7 +5,7 @@ have perl || return
_perlmodules() _perlmodules()
{ {
COMPREPLY=( $( compgen -P "$prefix" -W \ COMPREPLY=( $( compgen -P "$prefix" -W \
"$( ${1:-perl} ${BASH_COMPLETION%/*}/helpers/perl modules $cur )" \ "$( ${1:-perl} ${BASH_SOURCE[0]%/*}/../helpers/perl modules $cur )" \
-- "$cur" ) ) -- "$cur" ) )
__ltrim_colon_completions "$prefix$cur" __ltrim_colon_completions "$prefix$cur"
} }
@ -13,7 +13,7 @@ _perlmodules()
_perlfunctions() _perlfunctions()
{ {
COMPREPLY=( $( compgen -P "$prefix" -W \ COMPREPLY=( $( compgen -P "$prefix" -W \
"$( ${1:-perl} ${BASH_COMPLETION%/*}/helpers/perl functions $cur )" \ "$( ${1:-perl} ${BASH_SOURCE[0]%/*}/../helpers/perl functions $cur )" \
-- "$cur" ) ) -- "$cur" ) )
} }