--- pacman-bash_completion-011410 2010-01-14 18:14:27.790316391 -0430 +++ /etc/bash_completion.d/pacman 2010-01-14 18:11:09.000000000 -0430 @@ -13,11 +13,13 @@ local w r for (( w=0; w<${#COMP_WORDS[@]}-1; w++)); do - if (( w == COMP_CWORD )) || [[ w == -* ]]; then - continue - fi - for r in ${!COMPREPLY[@]}; do - [[ ${COMP_WORDS[w]} == ${COMPREPLY[r]} ]] && unset 'COMPREPLY[r]'; break + # Don't touch operands + [[ ${COMP_WORDS[w]} == -* ]] && continue + # Only deal with full matches + for r in "${!COMPREPLY[@]}"; do + if [[ ${COMP_WORDS[w]} == ${COMPREPLY[r]} ]]; then + unset 'COMPREPLY[r]'; break + fi done done } @@ -38,14 +40,15 @@ --noprogressbar --repackage --rmdeps --skipinteg --source --syncdeps ) + # First word check if (( COMP_CWORD == 1 )) && [[ $cur != -[^-]* ]]; then COMPREPLY=($(compgen -W "$(echo "${short[@]/#/-}" "${long[@]}")" -- "$cur")) return 0 - elif [[ $prev == @(--config|-*[^-]p*) ]]; then + # Complete filenames for selected options + elif [[ $prev == @(--config|-*([^- ])p*) ]]; then _filedir; _arch_rem_selected; return 0 else - for w in "${!COMP_WORDS[@]}"; do - (( w == COMP_CWORD || w == 0 )) && continue + for (( w=0; w<${#COMP_WORDS[@]}; w++)); do [[ ${COMP_WORDS[w]} == @(--@(help|cleancache)|-*[hC]*) ]] && return 0 for o in "${!long[@]}"; do if [[ ${COMP_WORDS[w]} == ${long[o]} ]]; then @@ -53,7 +56,7 @@ fi done for o in "${!short[@]}"; do - if [[ ${COMP_WORDS[w]} == -*([^-])${short[o]}* ]]; then + if [[ ${COMP_WORDS[w]} == -*([^- ])${short[o]}* ]]; then unset 'short[o]' fi done @@ -80,11 +83,11 @@ _pacman() { COMPREPLY=() - local prev cur query remove sync upgrade core common list w m o s + local prev cur query remove sync upgrade core common list w m o s=() prev=${COMP_WORDS[COMP_CWORD-1]} cur=`_get_cword` - # These are splitted in a subshell with IFS=' '. No point in listing + # These are split in a subshell with IFS=' '. No point in listing # them by \n since compgen -W can't handle spaces or new lines in # operands query=( '--changelog --check --deps --explicit --file --foreign --groups --info @@ -103,22 +106,20 @@ core=( --help --query --remove --sync --upgrade --version -Q -R -S -U -V -h ) - # First word check - if (( COMP_CWORD==1 )) && [[ $cur != -[^-]* ]]; then + if (( COMP_CWORD == 1 )) && [[ $cur != -[^-]* ]]; then COMPREPLY=($(compgen -W "$(echo "${core[@]}" '-h' '--help' )" -- "$cur")) return 0 - # Complete filenames for selected options - elif [[ $prev == @(-*([^-])[br]*|--@(config|logfile|root|dbpath|cachedir)) ]]; then + elif [[ $prev == @(-*([^- ])[br]*|--@(config|logfile|root|dbpath|cachedir)) ]]; then _filedir; _arch_rem_selected; return 0 # Main option check else for m in 'Q query' 'R remove' 'S sync' 'U upgrade' 'null'; do [[ $m == null ]] && return 0 - [[ $COMP_LINE == @(* -*([^-])${m% *}*|* --${m#* }*) ]] && break + [[ $COMP_LINE == @(* -*([^- ])${m% *}*|* --${m#* } *) ]] && break done fi - # See if $cur is an operand before calling pacman + # See if $cur is an operand before calling _pacman_pkg case $cur in --*) # Generate the list from the option arrays. eval is being using on @@ -126,8 +127,7 @@ # arrays; completely sanitized input command eval "list=($(command sed 's,.*,\${&[0]},' <<<"${m#* }"; IFS=' '; echo ${common[0]}))" # Parse previous options - for w in "${!COMP_WORDS[@]}"; do - (( w == COMP_CWORD || w == 0 )) && continue + for (( w=0; w<${#COMP_WORDS[@]}-1; w++)); do if [[ ${COMP_WORDS[w]} == --@(help|version) ]]; then return 0 fi @@ -143,39 +143,38 @@ -*) # Use the short array command eval "list=($(command sed 's,.*,\${&[1]},' <<<"${m#* }"; IFS=' '; echo ${common[1]}))" - for w in "${!COMP_WORDS[@]}"; do - (( w == COMP_CWORD || w == 0 )) && continue - if [[ ${COMP_WORDS[w]} == -*([^-])[hV]* ]]; then + for (( w=0; w<${#COMP_WORDS[@]}; w++)); do + if [[ ${COMP_WORDS[w]} == -*([^- ])[hV]* ]]; then return 0 fi for o in "${!list[@]}"; do - if [[ ${COMP_WORDS[w]} == -*([^-])${list[o]}* ]]; then + if [[ ${COMP_WORDS[w]} == -*([^- ])${list[o]}* ]]; then unset 'list[o]' fi done done # Allow special double options case ${m% *} in - Q) [[ $cur == *([^i])i*([^i]) ]] && s+=(i) ;; - R) [[ $cur == *([^d])d*([^d]) ]] && s+=(s) ;; - S) [[ $cur == *([^c])c*([^u]) ]] && s+=(c) - [[ $cur == *([^u])u*([^u]) ]] && s+=(u) ;; + Q) [[ $cur == *([^i ])i*([^i ]) ]] && s+=(i) ;; + R) [[ $cur == *([^d ])d*([^d ]) ]] && s+=(s) ;; + S) [[ $cur == *([^c ])c*([^u ]) ]] && s+=(c) + [[ $cur == *([^u ])u*([^u ]) ]] && s+=(u) ;; esac list=("${list[@]/#/$cur}" "${s[@]/#/$cur}") ;; - # The word isn't an operand; use pacman or file dir + # The word isn't an operand; use pacman or _filedir *) case ${m% *} in # The weak extglobs are due to a previous match already # confirming validity Q) case $COMP_LINE in - @(* -*([^-])g* *|* --groups *)) _pacman_pkg Qgq sort ;; - @(* -*([^-])o* *|* --owns *)) _filedir ;; - @(* -*([^-])p* *|* --file *)) _filedir '*.pkg.tar.gz' ;; - @(* -*([^-])u* *|* --upgrades *)) _pacman_pkg Quq ;; - *) _pacman_pkg Qq ;; + @(* -*([^- ])g*|* --groups *)) _pacman_pkg Qgq sort ;; + @(* -*([^- ])o*|* --owns *)) _filedir ;; + @(* -*([^- ])p*|* --file *)) _filedir '*.pkg.tar.gz' ;; + @(* -*([^- ])u*|* --upgrades *)) _pacman_pkg Quq ;; + *) _pacman_pkg Qq ;; esac ;; R) @@ -183,9 +182,9 @@ ;; S) case $COMP_LINE in - @(* -*([^-])l* *|* --list *)) _pacman_pkg Sl sort ;; - @(* -*([^-])g* *|* --groups *)) _pacman_pkg Sg ;; - *) _pacman_pkg Slq ;; + @(* -*([^- ])l*|* --list *)) _pacman_pkg Sl sort ;; + @(* -*([^- ])g*|* --groups *)) _pacman_pkg Sg ;; + *) _pacman_pkg Slq ;; esac ;; U)