[Bash-completion-devel] bug #311708: multiple bash_completion.d directories in $BASH_COMPLETION_DIR

Raph gibboris at gmail.com
Tue Feb 15 16:03:14 UTC 2011


just a ping (updated patch attached).

For reference: [#311708]
+
http://www.mail-archive.com/bash-completion-devel@lists.alioth.debian.org/msg01673.html

May also help solving [#312795]


regards

Raph



On Tue, Dec 29, 2009 at 11:05:27PM +0100, gibboris at gmail.com wrote:
> Hi,
> I rewrote the patch submitted in #311708.
> It lets an user to source /etc/bash_completion.d,
> ~/.bash_completion.d, ~/dev/bashcompgit/contrib, ...
> 
> I considere splitting $BASH_COMPLETION_DIR in several directories if the
> full variable isn't a valid directory as an enhancement.
> As I can't attach to closed bugs, patch is attached here.
> 
> Raph
-------------- next part --------------
commit 145ada9206dae5fafa4dadfcecbe3c86ab810dd7
Author: Rapha?l Droz <raphael.droz at gmail.com>
Date:   Tue Feb 15 16:59:41 2011 +0100

    Allow colon-separated BASH_COMPLETION_DIR (Alioth: #311708).

diff --git a/bash_completion b/bash_completion
index c4ae7c9..6c9f453 100644
--- a/bash_completion
+++ b/bash_completion
@@ -1652,30 +1652,43 @@ if [ ${#list[@]} -gt 0 ]; then
 fi
 unset list
 
+# $1: directory containing completion scripts
+load_completion_dir()
+{
+    local i
+    if [[ -d "$1" && -r "$1" && -x "$1" ]]; then
+        for i in $(LC_ALL=C command ls "$1"); do
+            i="$1/$i"
+            [[ ${i##*/} != @(*~|*.bak|*.swp|\#*\#|*.dpkg*|*.rpm@(orig|new|save)|Makefile*) \
+                && -f $i && -r $i ]] && . "$i"
+        done
+        return 0
+    fi
+    return 1
+}
+
 # source 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
-        i=$BASH_COMPLETION_COMPAT_DIR/$i
-        [[ ${i##*/} != @(*~|*.bak|*.swp|\#*\#|*.dpkg*|*.rpm@(orig|new|save)|Makefile*) \
-            && -f $i && -r $i ]] && . "$i"
-    done
-fi
-if [[ $BASH_COMPLETION_DIR != $BASH_COMPLETION_COMPAT_DIR && \
-    -d $BASH_COMPLETION_DIR && -r $BASH_COMPLETION_DIR && \
-    -x $BASH_COMPLETION_DIR ]]; then
-    for i in $(LC_ALL=C command ls "$BASH_COMPLETION_DIR"); do
-        i=$BASH_COMPLETION_DIR/$i
-        [[ ${i##*/} != @(*~|*.bak|*.swp|\#*\#|*.dpkg*|*.rpm@(orig|new|save)|Makefile*) \
-            && -f $i && -r $i ]] && . "$i"
-    done
+load_completion_dir "$BASH_COMPLETION_COMPAT_DIR"
+
+# other source(s) (directory or colon-separated list of directories)
+if [[ $BASH_COMPLETION_DIR != $BASH_COMPLETION_COMPAT_DIR ]]; then
+    # if we can't load $BASH_COMPLETION_DIR, then split the variable
+    if ! load_completion_dir "$BASH_COMPLETION_DIR"; then
+        # and attempt to load each part...
+        # (spaces in completion directories would mess it up)
+        for each_comp_dir in ${BASH_COMPLETION_DIR//:/ }; do
+            # but ignore if == $BASH_COMPLETION_COMPAT_DIR which is already loaded
+            [[ $each_comp_dir != $BASH_COMPLETION_COMPAT_DIR ]] && \
+                load_completion_dir "$each_comp_dir"
+        done
+        unset each_comp_dir
+    fi
 fi
-unset i
 
 # source user completion file
 [[ $BASH_COMPLETION != ~/.bash_completion && -r ~/.bash_completion ]] \
     && . ~/.bash_completion
-unset -f have
+unset -f have load_completion_dir
 unset UNAME USERLAND have
 
 set $BASH_COMPLETION_ORIGINAL_V_VALUE


More information about the Bash-completion-devel mailing list