--- bash_completion 2009-09-29 21:08:22.000000000 -0430 +++ /etc/bash_completion.d/pacman 2009-12-16 20:39:42.000000000 -0430 @@ -14,9 +14,9 @@ # (Adapted from bash_completion by Ian Macdonald ) # This removes any options from the list of completions that have # already been specified on the command line. - COMPREPLY=($(echo "${COMP_WORDS[@]}" | \ + COMPREPLY=($(/bin/echo "${COMP_WORDS[@]}" | \ (while read -d ' ' i; do - [ "${i}" == "" ] && continue + [[ "${i}" == "" ]] && continue # flatten array with spaces on either side, # otherwise we cannot grep on word boundaries of # first and last word @@ -30,45 +30,27 @@ _available_repos () { - COMPREPLY=( $( compgen -W "$(grep '\[' /etc/pacman.conf | grep -v -e 'options' -e '^#' | tr -d '[]' )" -- $cur ) ) + COMPREPLY=( $( compgen -W "$(/usr/bin/pacman -Sl | /bin/sed 's|\s.*||' | /usr/bin/uniq )" -- $cur ) ) } _installed_pkgs () { - local installed_pkgs - installed_pkgs=$( ls /var/lib/pacman/local/ ) - COMPREPLY=( $( compgen -W "$( for i in $installed_pkgs; do echo ${i%-*-*}; done )" -- $cur ) ) + COMPREPLY=( $( compgen -W "$( /usr/bin/pacman -Qq )" -- $cur ) ) } _available_pkgs () { - #find balks easilly on a find /foo/*/* type dir, especially one like - # /var/lib/pacman/*/* - # This little change-up removes the find *and* only uses enabled repos - local available_pkgs - local enabled_repos - enabled_repos=$( grep '\[' /etc/pacman.conf | grep -v -e 'options' -e '^#' | tr -d '[]' ) - available_pkgs=$( for r in $enabled_repos; do echo /var/lib/pacman/sync/$r/*; done ) - COMPREPLY=( $( compgen -W "$( for i in $available_pkgs; do j=${i##*/}; echo ${j%-*-*}; done )" -- $cur ) ) + COMPREPLY=( $( compgen -W "$( /usr/bin/pacman -Sql )" -- $cur ) ) } _installed_groups () { - local installed_groups - installed_groups=$( find /var/lib/pacman/local -name desc -exec sed -ne '/%GROUPS%/,/^$/{//d; p}' {} \; | sort -u ) - COMPREPLY=( $( compgen -W "$( for i in $installed_groups; do echo ${i%-*-*}; done )" -- $cur ) ) + COMPREPLY=( $( compgen -W "$( /usr/bin/pacman -Qg | /bin/sed 's|\s.*||' | /usr/bin/uniq )" -- $cur ) ) } _available_groups () { - #find balks easilly on a find /foo/*/* type dir, especially one like - # /var/lib/pacman/*/* - # This little change-up removes the find *and* only uses enabled repos - local available_groups - local enabled_repos - enabled_repos=$( grep '\[' /etc/pacman.conf | grep -v -e 'options' -e '^#' | tr -d '[]' ) - available_groups=$( for r in $enabled_repos; do sed '/%GROUPS%/,/^$/{//d; p}' /var/lib/pacman/sync/$r/*/desc | sort -u; done ) - COMPREPLY=( $( compgen -W "$( for i in $available_groups; do echo ${i%-*-*}; done )" -- $cur ) ) + COMPREPLY=( $( compgen -W "$( /usr/bin/pacman -Sg )" -- $cur ) ) } ## makepkg completion @@ -126,7 +108,7 @@ str="${1}" shift 1 for c in "${@}"; do - if [ $(expr index "${str}" "${c}") -gt 0 ]; then + if [[ $(/usr/bin/expr index "${str}" "${c}") -gt 0 ]]; then return 0 fi done @@ -193,15 +175,15 @@ esac arglen=$(( ${#toparse}-1 )) - for c in $(seq 0 "${arglen}"); do + for c in $(/usr/bin/seq 0 "${arglen}"); do arg=${toparse:$c:1} - [ "${arg}" != "-" ] && mod="${mod}${arg}" + [[ "${arg}" != "-" ]] && mod="${mod}${arg}" done done cur=${COMP_WORDS[COMP_CWORD]} - if [ $COMP_CWORD -eq 1 ] && [[ "$cur" == -* ]]; then + if [[ $COMP_CWORD -eq 1 ]] && [[ "$cur" == -* ]]; then COMPREPLY=( $( compgen -W '\ -h --help \ -Q --query \ @@ -352,6 +334,8 @@ S) if _instring $mod l; then _available_repos + elif _instring $mod g; then + _available_groups else _available_pkgs fi