Hello bash-completion-devel List, I'm Dams.
Please consider the following patch, which makes bash-completion more failglob compliant. Let me explains the changes: * When performing "unset array[key]", before running unset, globbing is performed, and since [] are part of the globbing syntax, bash raises an error and the unset is not performed. * failglob has an higher priority than nullglob. A globbing will fail even if nullglob is enabled when failglob is enabled, so you have to disable failglob * And when doing "eval array[key]=\${array2[i]}", before attempting the eval, bash attempts to glob (like in the unset case) both the [key] and [i]. bash 3.1 has introduced the very nice "printf -v var" feature which is 1. easier to read (imho : no funny backslashing), 2. faster than eval and 3. way more reliable, so i'm using it here. I haven't detected any regression in the runCompletion test suite, but I may have done it wrong. Regards, D diff --git a/bash_completion b/bash_completion index 3360873..08ce365 100644 --- a/bash_completion +++ b/bash_completion @@ -264,7 +264,7 @@ __reassemble_comp_words_by_ref() [[ $line != [$' \t']* ]] && (( j >= 2 )) && ((j--)) # Append word separator to current or new word ref="$2[$j]" - eval $2[$j]=\${!ref}\${COMP_WORDS[i]} + printf -v "$2[$j]" %s "${!ref}${COMP_WORDS[i]}" # Indicate new cword [[ $i == $COMP_CWORD ]] && eval $3=$j # Remove optional whitespace + word separator from line copy @@ -278,7 +278,7 @@ __reassemble_comp_words_by_ref() done # Append word to current word ref="$2[$j]" - eval $2[$j]=\${!ref}\${COMP_WORDS[i]} + printf -v "$2[$j]" %s "${!ref}${COMP_WORDS[i]}" # Remove optional whitespace + word from line copy line=${line#*"${COMP_WORDS[i]}"} # Indicate new cword @@ -287,7 +287,9 @@ __reassemble_comp_words_by_ref() [[ $i == $COMP_CWORD ]] && eval $3=$j else # No, list of word completions separators hasn't changed; - eval $2=\( \"\${COMP_WORDS[@]}\" \) + for i in "${!COMP_WORDS[@]}"; do + printf -v "$2[$i]" %s "${COMP_WORDS[$i]}" + done fi } # __reassemble_comp_words_by_ref() @@ -634,7 +636,7 @@ _variables() _filedir for i in ${!COMPREPLY[@]}; do if [[ ${COMPREPLY[i]} == *.tab ]]; then - unset COMPREPLY[i] + unset 'COMPREPLY[i]' continue elif [[ -d ${COMPREPLY[i]} ]]; then COMPREPLY[i]+=/ @@ -1108,8 +1110,10 @@ _xinetd_services() local xinetddir=/etc/xinetd.d if [[ -d $xinetddir ]]; then local restore_nullglob=$(shopt -p nullglob); shopt -s nullglob + local restore_failglob=$(shopt -p failglob); shopt -u failglob local -a svcs=( $( printf '%s\n' $xinetddir/!($_backup_glob) ) ) $restore_nullglob + $restore_failglob COMPREPLY+=( $( compgen -W '${svcs[@]#$xinetddir/}' -- "$cur" ) ) fi } @@ -1122,8 +1126,10 @@ _services() _sysvdirs local restore_nullglob=$(shopt -p nullglob); shopt -s nullglob + local restore_failglob=$(shopt -p failglob); shopt -u failglob COMPREPLY=( $( printf '%s\n' ${sysvdirs[0]}/!($_backup_glob|functions) ) ) $restore_nullglob + $restore_failglob COMPREPLY+=( $( systemctl list-units --full --all 2>/dev/null | \ awk '$1 ~ /\.service$/ { sub("\\.service$", "", $1); print $1 }' ) ) @@ -1683,7 +1689,7 @@ _command_offset() COMP_WORDS[i]=${COMP_WORDS[i+$word_offset]} done for (( i; i <= COMP_CWORD; i++ )); do - unset COMP_WORDS[i] + unset 'COMP_WORDS[i]' done ((COMP_CWORD -= $word_offset)) -- Damien Nadé <dnade....@orange.com> Astek Sud-Est pour France Télécom - FT/OF/OFA/DMGP/PORTAIL/DOP/DEV/EAQS Sophia Antipolis - France / Tel : 04 97 46 28 74 _________________________________________________________________________________________________________________________ Ce message et ses pieces jointes peuvent contenir des informations confidentielles ou privilegiees et ne doivent donc pas etre diffuses, exploites ou copies sans autorisation. Si vous avez recu ce message par erreur, veuillez le signaler a l'expediteur et le detruire ainsi que les pieces jointes. Les messages electroniques etant susceptibles d'alteration, Orange decline toute responsabilite si ce message a ete altere, deforme ou falsifie. Merci. This message and its attachments may contain confidential or privileged information that may be protected by law; they should not be distributed, used or copied without authorisation. If you have received this email in error, please notify the sender and delete this message and its attachments. As emails may be altered, Orange is not liable for messages that have been modified, changed or falsified. Thank you. _______________________________________________ Bash-completion-devel mailing list Bash-completion-devel@lists.alioth.debian.org http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/bash-completion-devel