Hello,
attached is a patch which i would like you to review and comment on the changes
if they are worth to be included.
I did change the following:
1) The case statement at the top is there to check if the shell that sources is
interactive.
2) the test for $BASH_COMPLETION_COMPAT_DIR shall prevent sourcing completions
more then once.
3) There are some case where 'type' is used (which also return aliases) where
iiuc 'type -p' is intended.
4) Then there are some locale aware commands not protected by 'LC_ALL=c'.
5) Lastly iiuc $BASH_COMPLETION_COMPAT_DIR/$i should be escaped.
Finally a question e.g.:
if type -p foo; then
\foo
^- missing
There are cases where it explicitly tests for the on disk prog and then happily
accepts functions and aliases.
I wonder if makes sense to stay explicit and circumvent aliase and functions
defined by the user. If patches would be welcome i am willing to spend some time
on that.
kind regards,
Thilo
--- bash_completion.orig 2013-11-05 17:23:10.000000000 +0000
+++ bash_completion 2013-11-05 20:02:35.021256912 +0000
@@ -26,6 +26,14 @@
#
# RELEASE: 2.1
+case $- in
+ *i*) ;;
+ *) return 0 ;;
+esac
+
+[[ -n "${BASH_COMPLETION_COMPAT_DIR}" ]] && return 0
+
+
if [[ $- == *v* ]]; then
BASH_COMPLETION_ORIGINAL_V_VALUE="-v"
else
@@ -119,7 +127,7 @@
{
# 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
+ PATH=$PATH:/usr/sbin:/sbin:/usr/local/sbin type -p $1 &>/dev/null
}
# Backwards compatibility for compat completions that use have().
@@ -852,7 +860,7 @@
) )
# ARP cache
- COMPREPLY+=( $( { arp -an || ip neigh show; } 2>/dev/null | sed -ne \
+ COMPREPLY+=( $( { LC_ALL=C arp -an || ip neigh show; } 2>/dev/null | sed -ne \
"s/.*[[:space:]]\($re\)[[:space:]].*/\1/p" -ne \
"s/.*[[:space:]]\($re\)[[:space:]]*$/\1/p" ) )
@@ -918,11 +926,11 @@
local cmd PATH=$PATH:/sbin
if [[ ${1:-} == -w ]]; then
- cmd="iwconfig"
+ cmd="LC_ALL=C iwconfig"
elif [[ ${1:-} == -a ]]; then
- cmd="{ ifconfig || ip link show up; }"
+ cmd="{ LC_ALL=C ifconfig || ip link show up; }"
else
- cmd="{ ifconfig -a || ip link show; }"
+ cmd="{ LC_ALL=C ifconfig -a || ip link show; }"
fi
COMPREPLY=( $( eval $cmd 2>/dev/null | awk \
@@ -1072,9 +1080,9 @@
#
_uids()
{
- if type getent &>/dev/null; then
+ if type -p getent &>/dev/null; then
COMPREPLY=( $( compgen -W '$( getent passwd | cut -d: -f3 )' -- "$cur" ) )
- elif type perl &>/dev/null; then
+ elif type -p perl &>/dev/null; then
COMPREPLY=( $( compgen -W '$( perl -e '"'"'while (($uid) = (getpwent)[2]) { print $uid . "\n" }'"'"' )' -- "$cur" ) )
else
# make do with /etc/passwd
@@ -1086,10 +1094,10 @@
#
_gids()
{
- if type getent &>/dev/null; then
+ if type -p getent &>/dev/null; then
COMPREPLY=( $( compgen -W '$( getent group | cut -d: -f3 )' \
-- "$cur" ) )
- elif type perl &>/dev/null; then
+ elif type -p perl &>/dev/null; then
COMPREPLY=( $( compgen -W '$( perl -e '"'"'while (($gid) = (getgrent)[2]) { print $gid . "\n" }'"'"' )' -- "$cur" ) )
else
# make do with /etc/group
@@ -1559,7 +1567,7 @@
# Add hosts reported by avahi-browse, if desired and it's available.
if [[ ${COMP_KNOWN_HOSTS_WITH_AVAHI:-} ]] && \
- type avahi-browse &>/dev/null; then
+ type -p avahi-browse &>/dev/null; then
# The original call to avahi-browse also had "-k", to avoid lookups
# into avahi's services DB. We don't need the name of the service, and
# if it contains ";", it may mistify the result. But on Gentoo (at
@@ -1977,7 +1985,7 @@
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
- i=$BASH_COMPLETION_COMPAT_DIR/$i
+ i="$BASH_COMPLETION_COMPAT_DIR/$i"
[[ ${i##*/} != @($_backup_glob|Makefile*|$_blacklist_glob) \
&& -f $i && -r $i ]] && . "$i"
done
_______________________________________________
Bash-completion-devel mailing list
[email protected]
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/bash-completion-devel