diff -u bash-completion-20060301/debian/changelog bash-completion-20060301/debian/changelog --- bash-completion-20060301/debian/changelog +++ bash-completion-20060301/debian/changelog @@ -1,3 +1,20 @@ +bash-completion (20060301-3ubuntu2) hardy; urgency=low + + * Bugfix release: + - Fix _get_cword more + - Fix _command function to correctly prune the command line (LP: #103395) + - Remove newline from options pattern for dpkg (LP: #138312) + - Start readline-quoting arguments to compgen (LP: #123665) + - Save and restore -v shell option (LP: #205444) + - Prevent glob expansion in _filedir function (LP: #194419) + - Quote glob expression in tar completion function (LP: #194419) + - Complete AAS/SSA files for mplayer -sub (LP: #151086) + - Disable completion of postgresql users and databases (LP: #164772) + - Use files from UserKnownHostsFile options in addition to standard ones + (LP: #211180) + + -- Mika Fischer Sat, 05 Apr 2008 16:09:34 +0200 + bash-completion (20060301-3ubuntu1) hardy; urgency=low * Bug fix upload (LP: #194860) diff -u bash-completion-20060301/bash_completion bash-completion-20060301/bash_completion --- bash-completion-20060301/bash_completion +++ bash-completion-20060301/bash_completion @@ -25,7 +25,17 @@ # # RELEASE: 20060301 -[ -n "${BASH_COMPLETION_DEBUG:-}" ] && set -v || set +v +if [[ $- == *v* ]]; then + BASH_COMPLETION_ORIGINAL_V_VALUE="-v" +else + BASH_COMPLETION_ORIGINAL_V_VALUE="+v" +fi + +if [[ -n $BASH_COMPLETION_DEBUG ]]; then + set -v +else + set +v +fi # Alter the following to reflect the location of this file. # @@ -177,40 +187,61 @@ [[ "$( bind -v )" = *$1+([[:space:]])on* ]] } +# This function shell-quotes the argument +quote() +{ + echo \'${1//\'/\'\\\'\'}\' #'# Help vim syntax highlighting +} + +# This function quotes the argument in a way so that readline dequoting +# results in the original argument +quote_readline() +{ + local t="${1//\\/\\\\}" + echo \'${t//\'/\'\\\'\'}\' #'# Help vim syntax highlighting +} + +# This function shell-dequotes the argument +dequote() +{ + eval echo "$1" +} + + # Get the word to complete # This is nicer than ${COMP_WORDS[$COMP_CWORD]}, since it handles cases # where the user is completing in the middle of a word. # (For example, if the line is "ls foobar", # and the cursor is here --------> ^ # it will complete just "foo", not "foobar", which is what the user wants.) -# -# Accepts an optional parameter indicating which characters out of -# $COMP_WORDBREAKS should NOT be considered word breaks. This is useful -# for things like scp where we want to return host:path and not only path. _get_cword() { - local i - local WORDBREAKS=${COMP_WORDBREAKS} - if [ -n $1 ]; then - for (( i=0; i<${#1}; ++i )); do - local char=${1:$i:1} - WORDBREAKS=${WORDBREAKS//$char/} + if [[ "${#COMP_WORDS[COMP_CWORD]}" -eq 0 ]] || [[ "$COMP_POINT" == "${#COMP_LINE}" ]]; then + echo "${COMP_WORDS[COMP_CWORD]}" + else + local i + local cur="$COMP_LINE" + local index="$COMP_POINT" + for (( i = 0; i <= COMP_CWORD; ++i )); do + while [[ "${#cur}" -ge ${#COMP_WORDS[i]} ]] && [[ "${cur:0:${#COMP_WORDS[i]}}" != "${COMP_WORDS[i]}" ]]; do + cur="${cur:1}" + index="$(( index - 1 ))" + done + if [[ "$i" -lt "$COMP_CWORD" ]]; then + local old_size="${#cur}" + cur="${cur#${COMP_WORDS[i]}}" + local new_size="${#cur}" + index="$(( index - old_size + new_size ))" + fi done - fi - local cur=${COMP_LINE:0:$COMP_POINT} - local tmp="${cur}" - local word_start=`expr "$tmp" : '.*['"${WORDBREAKS}"']'` - while [ "$word_start" -ge 2 ]; do - local char=${cur:$(( $word_start - 2 )):1} - if [ "$char" != "\\" ]; then - break - fi - tmp=${COMP_LINE:0:$(( $word_start - 2 ))} - word_start=`expr "$tmp" : '.*['"${WORDBREAKS}"']'` - done - cur=${cur:$word_start} - echo $cur + if [[ "${COMP_WORDS[COMP_CWORD]:0:${#cur}}" != "$cur" ]]; then + # We messed up! At least return the whole word so things keep working + echo "${COMP_WORDS[COMP_CWORD]}" + else + echo "${cur:0:$index}" + fi + fi } @@ -221,23 +252,23 @@ # _filedir() { - local IFS=$'\t\n' xspec #glob + local IFS=$'\t\n' xspec _expand || return 0 - #glob=$(set +o|grep noglob) # save glob setting. - #set -f # disable pathname expansion (globbing) - - if [ "${1:-}" = -d ]; then - COMPREPLY=( ${COMPREPLY[@]:-} $( compgen -d -- $cur ) ) - #eval "$glob" # restore glob setting. - return 0 + local toks=( ) tmp + while read -r tmp; do + [[ -n $tmp ]] && toks[${#toks[@]}]=$tmp + done < <( compgen -d -- "$(quote_readline "$cur")" ) + + if [[ "$1" != -d ]]; then + xspec=${1:+"!*.$1"} + while read -r tmp; do + [[ -n $tmp ]] && toks[${#toks[@]}]=$tmp + done < <( compgen -f -X "$xspec" -- "$(quote_readline "$cur")" ) fi - xspec=${1:+"!*.$1"} # set only if glob passed in as $1 - COMPREPLY=( ${COMPREPLY[@]:-} $( compgen -f -X "$xspec" -- "$cur" ) \ - $( compgen -d -- "$cur" ) ) - #eval "$glob" # restore glob setting. + COMPREPLY=( "${COMPREPLY[@]}" "${toks[@]}" ) } # This function completes on signal names @@ -306,12 +337,12 @@ # _expand() { - [ "$cur" != "${cur%\\}" ] && cur="$cur\\" + # FIXME: Why was this here? + # [ "$cur" != "${cur%\\}" ] && cur="$cur\\" # expand ~username type directory specifications if [[ "$cur" == \~*/* ]]; then eval cur=$cur - elif [[ "$cur" == \~* ]]; then cur=${cur#\~} COMPREPLY=( $( compgen -P '~' -u $cur ) ) @@ -385,7 +416,7 @@ COMPREPLY=( $( builtin echo $sysvdir/!(*.rpmsave|*.rpmorig|*~|functions)) ) if [ -d $famdir ]; then - COMPREPLY=( ${COMPREPLY[@]} $( builtin echo $famdir/!(*.rpmsave|*.rpmorig|*~)) ) + COMPREPLY=( "${COMPREPLY[@]}" $( builtin echo $famdir/!(*.rpmsave|*.rpmorig|*~)) ) fi COMPREPLY=( $( compgen -W '${COMPREPLY[@]#@($sysvdir|$famdir)/}' -- $cur ) ) @@ -1041,7 +1072,7 @@ # remove word from list of completions COMPREPLY=( ${COMPREPLY/ ${i%% *} / } ) done - echo ${COMPREPLY[@]}) + echo "${COMPREPLY[@]}") ) ) _filedir @@ -1070,7 +1101,7 @@ essid) COMPREPLY=( $( compgen -W 'on off any' -- $cur ) ) if [ -n "${COMP_IWLIST_SCAN:-}" ]; then - COMPREPLY=( ${COMPREPLY[@]:-} \ + COMPREPLY=( "${COMPREPLY[@]}" \ $( iwlist ${COMP_WORDS[1]} scan | \ awk -F '"' '/ESSID/ {print $2}' | \ grep "^$cur" )) @@ -1097,7 +1128,7 @@ ap) COMPREPLY=( $( compgen -W 'on off any' -- $cur ) ) if [ -n "${COMP_IWLIST_SCAN:-}" ]; then - COMPREPLY=( ${COMPREPLY[@]:-} \ + COMPREPLY=( "${COMPREPLY[@]}" \ $( iwlist ${COMP_WORDS[1]} scan | \ awk -F ': ' '/Address/ {print $2}' | \ grep "^$cur" ) ) @@ -1106,7 +1137,7 @@ ;; rate) COMPREPLY=( $( compgen -W 'auto fixed' -- $cur ) ) - COMPREPLY=( ${COMPREPLY[@]:-} \ + COMPREPLY=( "${COMPREPLY[@]}" \ $( iwlist ${COMP_WORDS[1]} rate | \ awk '/^[[:space:]]*[0-9]/ {print $1"M"}' | \ grep "^$cur" ) ) @@ -1391,7 +1422,7 @@ fi qfile=0 - for idx in ${COMP_WORDS[@]}; do + for idx in "${COMP_WORDS[@]}"; do [[ "$idx" = -q ]] && qfile=1 && break done if [[ $qfile == 1 ]]; then @@ -1535,7 +1566,7 @@ cur=`_get_cword` count=0 - for i in ${COMP_WORDS[@]}; do + for i in "${COMP_WORDS[@]}"; do [ $count -eq $COMP_CWORD ] && break # Last parameter was the CVSROOT, now go back to mode selection if [ "${COMP_WORDS[((count))]}" == "$cvsroot" -a "$mode" == "cvsroot" ]; then @@ -1605,7 +1636,7 @@ ;; esac elif [[ "$i" = -* ]]; then - flags=( ${flags[@]:-} $i ) + flags=( "${flags[@]}" $i ) fi count=$((++count)) done @@ -1619,7 +1650,7 @@ [ -z "$cur" ] && \ files=$( command ls -Ad !(CVS) ) || \ files=$( command ls -d ${cur}* 2>/dev/null ) - for i in ${entries[@]:-}; do + for i in "${entries[@]}"; do files=( ${files[@]/#$i//} ) done COMPREPLY=( $( compgen -W '${files[@]}' -- \ @@ -1713,8 +1744,8 @@ if [ $COMP_CWORD -gt 1 -a -r ${prefix:-}CVS/Entries ]; then get_entries # find out what files are missing - for i in ${entries[@]}; do - [ ! -r "$i" ] && miss=( ${miss[@]:-} $i ) + for i in "${entries[@]}"; do + [ ! -r "$i" ] && miss=( "${miss[@]}" $i ) done COMPREPLY=( $(compgen -W '${miss[@]:-}' -- $cur) ) fi @@ -1805,7 +1836,7 @@ COMPREPLY=( $( rpm -qa $nodig $nosig --queryformat '%{group}\n' | \ grep "^$cur" ) ) # backslash escape spaces and translate newlines to tabs - COMPREPLY=( $( echo ${COMPREPLY[@]} | sed 's/ /\\ /g' | tr '\n' '\t' ) ) + COMPREPLY=( $( echo "${COMPREPLY[@]}" | sed 's/ /\\ /g' | tr '\n' '\t' ) ) } # rpm(8) completion @@ -2476,33 +2507,29 @@ user_kh=$( eval echo $( sed -ne 's/^[ \t]*[Uu][Ss][Ee][Rr][Kk][Nn][Oo][Ww][Nn][Hh][Oo][Ss][Tt][Ss][Ff][Ii][Ll][Ee]['"$'\t '"']*\(.*\)$/\1/p' "${config[@]}" ) ) fi - # choose which global known hosts file to use - if [ -r "$global_kh" ]; then - kh=( "$global_kh" ) - else - [ -r /etc/ssh/ssh_known_hosts ] && - kh=( ${kh[@]} /etc/ssh/ssh_known_hosts ) - [ -r /etc/ssh/ssh_known_hosts2 ] && - kh=( ${kh[@]} /etc/ssh/ssh_known_hosts2 ) - [ -r /etc/known_hosts ] && - kh=( ${kh[@]} /etc/known_hosts ) - [ -r /etc/known_hosts2 ] && - kh=( ${kh[@]} /etc/known_hosts2 ) - [ -d /etc/ssh2/knownhosts ] && - khd=( ${khd[@]} /etc/ssh2/knownhosts/*pub ) - fi - - # choose which user known hosts file to use - if [ -r "$user_kh" ]; then - kh=( ${kh[@]} "$user_kh" ) - else - [ -r ~/.ssh/known_hosts ] && - kh=( ${kh[@]} ~/.ssh/known_hosts ) - [ -r ~/.ssh/known_hosts2 ] && - kh=( ${kh[@]} ~/.ssh/known_hosts2 ) - [ -d ~/.ssh2/hostkeys ] && - khd=( ${khd[@]} ~/.ssh2/hostkeys/*pub ) - fi + # Global known_hosts files + [ -r "$global_kh" ] && + kh=( "${kh[@]}" "$global_kh" ) + [ -r /etc/ssh/ssh_known_hosts ] && + kh=( "${kh[@]}" /etc/ssh/ssh_known_hosts ) + [ -r /etc/ssh/ssh_known_hosts2 ] && + kh=( "${kh[@]}" /etc/ssh/ssh_known_hosts2 ) + [ -r /etc/known_hosts ] && + kh=( "${kh[@]}" /etc/known_hosts ) + [ -r /etc/known_hosts2 ] && + kh=( "${kh[@]}" /etc/known_hosts2 ) + [ -d /etc/ssh2/knownhosts ] && + khd=( "${khd[@]}" /etc/ssh2/knownhosts/*pub ) + + # User known_hosts files + [ -r "$user_kh" ] && + kh=( "${kh[@]}" "$user_kh" ) + [ -r ~/.ssh/known_hosts ] && + kh=( "${kh[@]}" ~/.ssh/known_hosts ) + [ -r ~/.ssh/known_hosts2 ] && + kh=( "${kh[@]}" ~/.ssh/known_hosts2 ) + [ -d ~/.ssh2/hostkeys ] && + khd=( "${khd[@]}" ~/.ssh2/hostkeys/*pub ) # If we have known_hosts files to use if [ ${#kh[@]} -gt 0 -o ${#khd[@]} -gt 0 ]; then @@ -2532,18 +2559,18 @@ /^[^|]/ {for (i=1; i<=2; ++i) { \ gsub(" .*$", "", $i); \ if ($i ~ /'$cur'/) {print $i} \ - }}' ${kh[@]} 2>/dev/null ) ) + }}' "${kh[@]}" 2>/dev/null ) ) fi if [ ${#khd[@]} -gt 0 ]; then # Needs to look for files called # .../.ssh2/key_22_.pub # dont fork any processes, because in a cluster environment, # there can be hundreds of hostkeys - for i in ${khd[@]} ; do + for i in "${khd[@]}" ; do if [[ "$i" == *key_22_$curd*.pub ]] && [ -r "$i" ] ; then host=${i/#*key_22_/} host=${host/%.pub/} - COMPREPLY=( ${COMPREPLY[@]} $host ) + COMPREPLY=( "${COMPREPLY[@]}" $host ) fi done fi @@ -2552,11 +2579,11 @@ if [ ${#config[@]} -gt 0 ] && [ -n "$aliases" ]; then local host_aliases=$( sed -ne 's/^[Hh][Oo][Ss][Tt]\([Nn][Aa][Mm][Ee]\)\?['"$'\t '"']\+\([^*?]*\)$/\2/p' "${config[@]}" ) hosts=$( compgen -W "$host_aliases" -- $ocur ) - COMPREPLY=( ${COMPREPLY[@]} $hosts ) + COMPREPLY=( "${COMPREPLY[@]}" $hosts ) fi # Now add results of normal hostname completion - COMPREPLY=( ${COMPREPLY[@]} $( compgen -A hostname -- $ocur ) ) + COMPREPLY=( "${COMPREPLY[@]}" $( compgen -A hostname -- $ocur ) ) # apply suffix for (( i=0; i < ${#COMPREPLY[@]}; i++ )); do @@ -2599,7 +2626,7 @@ _known_hosts -a [ $COMP_CWORD -eq 1 ] || \ - COMPREPLY=( ${COMPREPLY[@]} $( compgen -c -- $cur ) ) + COMPREPLY=( "${COMPREPLY[@]}" $( compgen -c -- $cur ) ) esac return 0 @@ -2613,7 +2640,7 @@ local cur userhost path COMPREPLY=() - cur=`_get_cword ":"` + cur=`_get_cword` _expand || return 0 @@ -2640,7 +2667,7 @@ [[ "$cur" == */* ]] || _known_hosts -c -a local IFS=$'\t\n' - COMPREPLY=( ${COMPREPLY[@]} $( command ls -aF1d $cur* \ + COMPREPLY=( "${COMPREPLY[@]}" $( command ls -aF1d $cur* \ 2>/dev/null | sed \ -e "s/[][(){}<>\",:;^&!$&=?\`|\\ ']/\\\\&/g" \ -e 's/[*@|=]$//g' -e 's/[^\/]$/& /g' ) ) @@ -2772,7 +2799,7 @@ # remove word from list of completions COMPREPLY=( ${COMPREPLY/ $i / } ) done - echo ${COMPREPLY[@]}) + echo "${COMPREPLY[@]}") ) ) return 0 } @@ -2931,7 +2958,7 @@ fi # file completion on relevant files - _filedir $ext + _filedir "$ext" return 0 } @@ -3103,7 +3130,7 @@ # we have a CDPATH, so loop on its contents for i in ${CDPATH//:/$'\t'}; do # create an array of matched subdirs - k=${#COMPREPLY[@]} + k="${#COMPREPLY[@]}" for j in $( compgen -d $i/$cur ); do if [[ ( $mark_symdirs && -h $j || $mark_dirs && ! -h $j ) && ! -d ${j#$i/} ]]; then j="${j}/" @@ -3129,6 +3156,37 @@ complete -F _cd $nospace $filenames cd fi +_remove_comp_word() +{ + if [[ COMP_CWORD -eq 0 ]]; then + return + elif [[ ${#COMP_WORDS[@]} -ge 2 ]]; then + local old_cw0="${COMP_WORDS[0]}" + local new_cw0="${COMP_WORDS[1]}" + local old_length="${#COMP_LINE}" + COMP_LINE=${COMP_LINE#${old_cw0}} + local head=${COMP_LINE:0:${#new_cw0}} + local i=1 + while [[ $head != $new_cw0 ]]; do + COMP_LINE=${COMP_LINE:1} + head=${COMP_LINE:0:${#new_cw0}} + if (( ++i > 10 )); then + break + fi + done + local new_length="${#COMP_LINE}" + COMP_POINT=$(( COMP_POINT + new_length - old_length)) + + COMP_CWORD=$(( COMP_CWORD - 1 )) + for (( i=0; i < ${#COMP_WORDS[@]} - 1; ++i )); do + COMP_WORDS[i]="${COMP_WORDS[i+1]}" + done + unset COMP_WORDS[${#COMP_WORDS[@]}-1] + else + return + fi +} + # A meta-command completion function for commands like sudo(8), which need to # first complete on a command, then complete according to that command's own # completion definition - currently not quite foolproof (e.g. mount and umount @@ -3139,63 +3197,45 @@ local cur func cline cspec noglob cmd done i \ _COMMAND_FUNC _COMMAND_FUNC_ARGS + _remove_comp_word COMPREPLY=() cur=`_get_cword` # If the the first arguments following our meta-command-invoker are # switches, get rid of them. Most definitely not foolproof. done= while [ -z $done ] ; do - cmd=${COMP_WORDS[1]} - if [[ "$cmd" == -* ]] && [ $COMP_CWORD -gt 1 ]; then - for (( i=1 ; i/dev/null; then cspec=$( complete -p $cmd ) if [ "${cspec#* -F }" != "$cspec" ]; then - # complete -F - # # COMP_CWORD and COMP_WORDS() are not read-only, # so we can set them before handing off to regular # completion routine - # set current token number to 1 less than now - COMP_CWORD=$(( $COMP_CWORD - 1 )) - # get function name func=${cspec#*-F } func=${func%% *} - # get current command line minus initial command - cline="${COMP_LINE#*( )$1 }" - # save noglob state - shopt -qo noglob; noglob=$? - # turn on noglob, as things like 'sudo ls *' - # don't work otherwise - shopt -so noglob - # split current command line tokens into array - COMP_WORDS=( $cline ) - # reset noglob if necessary - [ $noglob -eq 1 ] && shopt -uo noglob - $func $cline - # This is needed in case user finished entering - # command and pressed tab (e.g. sudo ls ) - COMP_CWORD=$(( $COMP_CWORD > 0 ? $COMP_CWORD : 1 )) - cur=`_get_cword` - _COMMAND_FUNC=$func - _COMMAND_FUNC_ARGS=( $cmd $2 $3 ) - COMP_LINE=$cline - COMP_POINT=$(( ${COMP_POINT} - ${#1} - 1 )) - $func $cmd $2 $3 + + if [[ ${#COMP_WORDS[@]} -ge 2 ]]; then + $func $cmd "${COMP_WORDS[${#COMP_WORDS[@]}-1]}" "${COMP_WORDS[${#COMP_WORDS[@]}-2]}" + else + $func $cmd "${COMP_WORDS[${#COMP_WORDS[@]}-1]}" + fi + # remove any \: generated by a command that doesn't # default to filenames or dirnames (e.g. sudo chown) + # FIXME: I'm pretty sure this does not work! if [ "${cspec#*-o }" != "$cspec" ]; then cspec=${cspec#*-o } cspec=${cspec%% *} @@ -3312,7 +3352,7 @@ COMPREPLY=( $( compgen -W '-# -f -? -C -h -p -P -i -r -E -s -S -t -u \ -v -V -w' -- $cur ) ) - COMPREPLY=( ${COMPREPLY[@]} \ + COMPREPLY=( "${COMPREPLY[@]}" \ $( compgen -W 'create drop extended-status flush-hosts \ flush-logs flush-status flush-tables \ flush-threads flush-privileges kill \ @@ -4010,6 +4050,7 @@ have psql && { _pg_databases() { + return COMPREPLY=( $( psql -l 2>/dev/null | \ sed -e '1,/^-/d' -e '/^(/,$d' | \ awk '{print $1}' | grep "^$cur" ) ) @@ -4017,9 +4058,10 @@ _pg_users() { - COMPREPLY=( $( psql -qtc 'select usename from pg_user' template1 2>/dev/null | \ - grep "^ $cur" ) ) - [ ${#COMPREPLY[@]} -eq 0 ] && COMPREPLY=( $( compgen -u -- $cur ) ) + #COMPREPLY=( $( psql -qtc 'select usename from pg_user' template1 2>/dev/null | \ + # grep "^ $cur" ) ) + #[ ${#COMPREPLY[@]} -eq 0 ] && + COMPREPLY=( $( compgen -u -- $cur ) ) } # createdb(1) completion @@ -4276,8 +4318,7 @@ fi case "$prev" in - -@(c|i|A|I|f|e|x|X|-@(install|unpack|record-avail|contents|info| \ - fsys-tarfile|field|control|extract))) + -@(c|i|A|I|f|e|x|X|-@(install|unpack|record-avail|contents|info|fsys-tarfile|field|control|extract))) _filedir '?(u)deb' return 0 ;; @@ -4597,17 +4638,17 @@ for i in ${classpath//:/ }; do if [ -r $i ] && [[ "$i" == *.@(jar|zip) ]]; then if type zipinfo &> /dev/null; then - COMPREPLY=( ${COMPREPLY[@]} $( zipinfo -1 \ + COMPREPLY=( "${COMPREPLY[@]}" $( zipinfo -1 \ "$i" | grep "^$cur" | grep '\.class$' | \ grep -v "\\$" ) ) else - COMPREPLY=( ${COMPREPLY[@]} $( jar tf "$i" \ + COMPREPLY=( "${COMPREPLY[@]}" $( jar tf "$i" \ "$cur" | grep "\.class$" | grep -v "\\$" ) ) fi elif [ -d $i ]; then i=${i%/} - COMPREPLY=( ${COMPREPLY[@]} $( find "$i" -type f \ + COMPREPLY=( "${COMPREPLY[@]}" $( find "$i" -type f \ -path "$i/$cur*.class" 2>/dev/null | \ grep -v "\\$" | sed -e "s|^$i/||" ) ) fi @@ -4632,12 +4673,12 @@ # parse each sourcepath element for packages for i in ${sourcepath//:/ }; do if [ -d $i ]; then - COMPREPLY=( ${COMPREPLY[@]} $( command ls -F -d \ + COMPREPLY=( "${COMPREPLY[@]}" $( command ls -F -d \ $i/$cur* 2>/dev/null | sed -e 's|^'$i'/||' ) ) fi done # keep only packages - COMPREPLY=( $( echo ${COMPREPLY[@]} | tr " " "\n" | grep "/$" ) ) + COMPREPLY=( $( echo "${COMPREPLY[@]}" | tr " " "\n" | grep "/$" ) ) # remove packages extension COMPREPLY=( ${COMPREPLY[@]%/} ) # convert path syntax to package syntax @@ -4821,7 +4862,7 @@ shift while [[ "$1" ]]; do newconffiles=( $(sed -rn 's|^source[[:space:]]+([^[:space:]]+).*$|\1|p' $(eval echo $1) ) ) - for file in ${newconffiles[@]}; do + for file in "${newconffiles[@]}"; do [[ ! "$file" ]] || [[ "${sofar/ ${file} / }" != "$sofar" ]] && continue sofar="$sofar $file" @@ -4844,8 +4885,8 @@ conffiles=( $(eval _muttconffiles $muttrc $muttrc) ) aliases=( $( sed -rn 's|^alias[[:space:]]+([^[:space:]]+).*$|\1|p' \ - $(eval echo ${conffiles[@]}) ) ) - COMPREPLY=( ${COMPREPLY[@]} $( compgen -W "${aliases[*]}" -- $cur ) ) + $(eval echo "${conffiles[@]}") ) ) + COMPREPLY=( "${COMPREPLY[@]}" $( compgen -W "${aliases[*]}" -- $cur ) ) return 0 } @@ -4864,7 +4905,7 @@ sed -nr '2,$s|^([^[:space:]]+).*|\1|p' ) ) fi - COMPREPLY=( ${COMPREPLY[@]} $( compgen -W "${queryresults[*]}" \ + COMPREPLY=( "${COMPREPLY[@]}" $( compgen -W "${queryresults[*]}" \ -- $cur ) ) return 0 @@ -5320,7 +5361,7 @@ ;; *) _perlmodules - COMPREPLY=( ${COMPREPLY[@]} $( compgen -W '$( PAGER=cat man perl 2>/dev/null | sed -ne "/perl.*Perl overview/,/perlwin32/s/^[^a-z0-9]*\([a-z0-9]*\).*$/\1/p")' -- $cur ) ) + COMPREPLY=( "${COMPREPLY[@]}" $( compgen -W '$( PAGER=cat man perl 2>/dev/null | sed -ne "/perl.*Perl overview/,/perlwin32/s/^[^a-z0-9]*\([a-z0-9]*\).*$/\1/p")' -- $cur ) ) return 0 ;; @@ -5550,7 +5591,7 @@ COMPREPLY2=( $( egrep "^[^\|]+\|$portsdir$cur" < $indexfile | \ cut -d'|' -f2 ) ) COMPREPLY2=( ${COMPREPLY2[@]#$portsdir} ) - COMPREPLY=( ${COMPREPLY[@]} ${COMPREPLY2[@]} ) + COMPREPLY=( "${COMPREPLY[@]}" "${COMPREPLY2[@]}" ) return 0 } && @@ -5654,13 +5695,13 @@ return 0 ;; -sub) - _filedir '@(srt|SRT|sub|SUB|txt|TXT|utf|UTF|rar|RAR|mpsub|smi|js)' + _filedir '@(srt|SRT|sub|SUB|txt|TXT|utf|UTF|rar|RAR|mpsub|smi|js|ssa|SSA|aas|AAS)' return 0 ;; -vobsub) _filedir '@(idx|IDX|ifo|IFO|sub|SUB)' IFS=$'\t\n' - COMPREPLY=( $( for i in ${COMPREPLY[@]}; do + COMPREPLY=( $( for i in "${COMPREPLY[@]}"; do if [ -f $i -a -r $i ]; then echo ${i%.*} else @@ -5897,7 +5938,7 @@ -bps -oldpp -nozoom -noflip -nounicode \ -noutf8' -- $cur ) ) # add mplayer specific options - [[ "$cmd" == @(?(g)mplayer) ]] && COMPREPLY=( ${COMPREPLY[@]} \ + [[ "$cmd" == @(?(g)mplayer) ]] && COMPREPLY=( "${COMPREPLY[@]}" \ $(compgen -W '-autoq -autosync -benchmark \ -framedrop -h -help -hardframedrop \ -identify -input -lircconf -loop \ @@ -5928,7 +5969,7 @@ -aaosdcolor -aasubcolor -aadriver \ -aaextended -aaeight' -- $cur) ) # add mencoder specific options - [[ "$cmd" = mencoder ]] && COMPREPLY=( ${COMPREPLY[@]} \ + [[ "$cmd" = mencoder ]] && COMPREPLY=( "${COMPREPLY[@]}" \ $(compgen -W '-audio-density -audio-delay \ -audio-preload -divx4opts -endpos \ -ffourcc -include -info -lameopts \ @@ -6036,7 +6077,7 @@ -@(r|-recipient)) COMPREPLY=( $( compgen -W "$( gpg --list-keys 2>/dev/null | sed -ne 's@^pub.*<\([^>]*\)>.*$@\1@p')" -- "$cur" )) if [ -e ~/.gnupg/gpg.conf ]; then - COMPREPLY=( ${COMPREPLY[@]} $( compgen -W "$( sed -ne 's@^[ \t]*group[ \t][ \t]*\([^=]*\).*$@\1@p' ~/.gnupg/gpg.conf )" -- "$cur") ) + COMPREPLY=( "${COMPREPLY[@]}" $( compgen -W "$( sed -ne 's@^[ \t]*group[ \t][ \t]*\([^=]*\).*$@\1@p' ~/.gnupg/gpg.conf )" -- "$cur") ) fi return 0 ;; @@ -6216,10 +6257,10 @@ # files are always eligible completion _filedir # track options are always available - COMPREPLY=( ${COMPREPLY[@]} $( compgen -W '${track_options[@]}' -- $cur ) ) + COMPREPLY=( "${COMPREPLY[@]}" $( compgen -W '${track_options[@]}' -- $cur ) ) # general options are no more available after file or track option if [ $track_mode -eq 0 ]; then - COMPREPLY=( ${COMPREPLY[@]} \ + COMPREPLY=( "${COMPREPLY[@]}" \ $( compgen -W '${generic_options[@]}' -- $cur ) ) fi @@ -6948,7 +6989,7 @@ fi } -complete -F _aspell $default aspell +complete -F _aspell $filenames aspell } # xmms(1) completion @@ -9299,9 +9340,17 @@ xspec=${xspec#*-X } xspec=${xspec%% *} - COMPREPLY=( $( eval compgen -f -X "$xspec" -- \ - \"${cur#[\`\"\']}\" 2>/dev/null ) \ - $( compgen -d -- $cur ) ) + local toks=( ) tmp + + while read -r tmp; do + [[ -n $tmp ]] && toks[${#toks[@]}]=$tmp + done < <( compgen -d -- "$(quote_readline "$cur")" ) + + while read -r tmp; do + [[ -n $tmp ]] && toks[${#toks[@]}]=$tmp + done < <( eval compgen -f -X $xspec -- "\$(quote_readline "\$cur")" ) + + COMPREPLY=( "${toks[@]}" ) } list=( $( sed -ne '/^# START exclude/,/^# FINISH exclude/p' \ $BASH_COMPLETION | \ @@ -9314,16 +9363,16 @@ line=${line%# START exclude*} line=${line%# FINISH exclude*} line=${line##*\'} - list=( ${list[@]:-} $line ) + list=( "${list[@]}" $line ) done - echo ${list[@]} + echo "${list[@]}" ) ) ) # remove previous compspecs if [ ${#list[@]} -gt 0 ]; then eval complete -r ${list[@]} # install new compspecs - eval complete -F _filedir_xspec $filenames ${list[@]} + eval complete -F _filedir_xspec $filenames "${list[@]}" fi unset list @@ -9344,6 +9393,9 @@ unset UNAME RELEASE default dirnames filenames have nospace bashdefault \ plusdirs +set $BASH_COMPLETION_ORIGINAL_V_VALUE +unset BASH_COMPLETION_ORIGINAL_V_VALUE + ### Local Variables: ### mode: shell-script ### End: