Bugs item #311708, was changed at 2009-05-29 00:50 by Sung Pae
You can respond by visiting: 
https://alioth.debian.org/tracker/?func=detail&atid=413095&aid=311708&group_id=100114

Status: Closed
Priority: 3
Submitted By: Sung Pae (guns-guest)
Assigned to: Nobody (None)
Summary: [PATCH] Make BASH_COMPLETION_DIR an array 
Distribution: None
Originally reported in: None
Milestone: None
Status: None
Original bug number: 


Initial Comment:
Hi, very glad to see progress on the bash-completion project!

I have been rolling my own version of Ian McDonald's bash-completion with my 
shell environment / software distribution application, and would love to see 
some of my favorite changes incorporated into the main tree.

One of those is setting BASH_COMPLETION_DIR as an array so that multiple bash 
completion directories can be sourced. This is a simple change, has no ill 
effects for regular one-directory use, and allows admins to source 
/usr/local/etc/bash_completion.d, /opt/*/etc/bash_completion.d, et cetera, as 
well as the main completion directory.

This would also encourage the user to create separate files for completions, 
instead of using ./.bash_completion; I imagine this will be helpful in the 
future, when dynamic loading of completion files is realized.


----------------------------------------------------------------------

Comment By: Sung Pae (guns-guest)
Date: 2009-10-25 02:21

Message:
Regarding the previous patch:

If colon-delimited paths are going to be added to BASH_COMPLETION_DIR, it 
should probably be sourced backwards through the paths, so that functions 
defined multiple times by different files overwrite each other such that the 
first path in BASH_COMPLETION_DIR has precedence.

--

IFS=':'; BASH_COMPLETION_DIR_ARY=($BASH_COMPLETION_DIR); unset IFS
for ((i = ${#bash_completion_dir_a...@]}-1; i >= 0; --i)); do
    DIR="${BASH_COMPLETION_DIR_ARY[i]}"
    if [ -d $DIR -a -r $DIR -a $DIR != $BASH_COMPLETION_COMPAT_DIR -a -x $DIR 
]; then
        for FILE in $(LC_ALL=C command ls $DIR); do
            FILE=$DIR/$FILE
            [[ ${FILE##*/} != 
@(*~|*.bak|*.swp|\#*\#|*.dpkg*|*.rpm@(orig|new|save)) ]] &&
            [ \( -f $FILE -o -h $FILE \) -a -r $FILE ] && . $FILE
        done
    fi
done
unset i BASH_COMPLETION_DIR_ARY DIR FILE

--

There's probably a better solution to the problem of conflicting completion 
files.


----------------------------------------------------------------------

Comment By: Raphaƫl Droz (gibboris-guest)
Date: 2009-07-22 03:48

Message:
Here comes a patch that modify bash_completion to allow a colon-separated 
$BASH_COMPLETION_DIR
(don't know how to attach something)

--- bash_completion.old 2009-07-22 08:35:03.000000000 +0000
+++ bash_completion     2009-07-22 08:39:46.000000000 +0000
@@ -1537,15 +1537,15 @@
                        [ \( -f $i -o -h $i \) -a -r $i ] && . $i               
        done
 fi
-if [ -d $BASH_COMPLETION_DIR -a -r $BASH_COMPLETION_DIR -a \
-     $BASH_COMPLETION_DIR != $BASH_COMPLETION_COMPAT_DIR -a \
-     -x $BASH_COMPLETION_DIR ]; then
-       for i in $BASH_COMPLETION_DIR/*; do
-               [[ ${i##*/} != 
@(*~|*.bak|*.swp|\#*\#|*.dpkg*|*.rpm@(orig|new|save)) ]] &&
+for j in ${BASH_COMPLETION_DIR[*]//:/ }; do
+       if [ -d $j -a -r $j -a $j != $BASH_COMPLETION_COMPAT_DIR -a -x $j ]; 
then
+               for i in $j/*; do
+                       [[ ${i##*/} != 
@(*~|*.bak|*.swp|\#*\#|*.dpkg*|*.rpm@(orig|new|save)) ]] &&
                        [ \( -f $i -o -h $i \) -a -r $i ] && . $i
-       done
-fi
-unset i
+               done
+       fi
+done
+unset i j
 
 # source user completion file
 [ $BASH_COMPLETION != ~/.bash_completion -a -r ~/.bash_completion ] 

----------------------------------------------------------------------

Comment By: Sung Pae (guns-guest)
Date: 2009-05-29 17:24

Message:
BASH_COMPLETION_DIR as an array has been working well for me so far, but I see 
how it doesn't adapt to future uses (dynamic completions?). Totally agree that 
colon delimited strings are more workable in bash until arrays are given a 
proper implementation.

Thanks for the link. I see that you guys are looking farther ahead than I 
imagined. Very exciting news, good to see smart hackers on this project.

----------------------------------------------------------------------

Comment By: Freddy Vulto (fvu-guest)
Date: 2009-05-29 15:18

Message:
Hi, problem with real bash arrays is that they're not exportable to a subshell, 
as opposed to a colon-separated array/string:

   $ export a=(foo bar) b=foo:bar
   $ echo $...@]} $b
   foo bar foo:bar
   $ bash
   $ echo $...@]} $b
   foo:bar  # $a is gone

This might not be a problem if completion is always sourced within the current 
shell, but having to set BASH_COMPLETION_DIR in the current shell will fail 
anyone out there who's relying on export.

So while an array is good, I prefer the colon-separated notation - as in $PATH. 
 Doing so will probably be part of the "New Directory Layout" release.  See 
also: http://wiki.debian.org/Teams/BashCompletion/Proposals/NewDirectoryLayout

Thanks, Freddy

----------------------------------------------------------------------

Comment By: Sung Pae (guns-guest)
Date: 2009-05-29 01:50

Message:
Oops, didn't see that the first check was wrapped in a [ ] test. Trying to 
upload updated patch

----------------------------------------------------------------------

You can respond by visiting: 
https://alioth.debian.org/tracker/?func=detail&atid=413095&aid=311708&group_id=100114

_______________________________________________
Bash-completion-devel mailing list
[email protected]
http://lists.alioth.debian.org/mailman/listinfo/bash-completion-devel

Reply via email to