1 # vim: set ft=sh ts=2 sw=2 et:
2 # file: /etc/bash_completion.d/pacman
4 # Bash completion for pacman
5 # Original: Manolis Tzanidakis <mtzanidakis@freemail.gr>
7 # Distributed under the terms of the GNU General Public License, v2 or later.
14 # (Adapted from bash_completion by Ian Macdonald <ian@caliban.org>)
15 # This removes any options from the list of completions that have
16 # already been specified on the command line.
17 COMPREPLY=($(echo "${COMP_WORDS[@]}" | \
18 (while read -d ' ' i; do
19 [ "${i}" == "" ] && continue
20 # flatten array with spaces on either side,
21 # otherwise we cannot grep on word boundaries of
23 COMPREPLY=" ${COMPREPLY[@]} "
24 # remove word from list of completions
25 COMPREPLY=(${COMPREPLY/ ${i%% *} / })
27 echo ${COMPREPLY[@]})))
33 COMPREPLY=( $( compgen -W "$(grep '\[' /etc/pacman.conf | grep -v -e 'options' -e '^#' | tr -d '[]' )" -- $cur ) )
39 installed_pkgs=$( ls /var/lib/pacman/local/ )
40 COMPREPLY=( $( compgen -W "$( for i in $installed_pkgs; do echo ${i%-*-*}; done )" -- $cur ) )
45 #find balks easilly on a find /foo/*/* type dir, especially one like
47 # This little change-up removes the find *and* only uses enabled repos
50 enabled_repos=$( grep '\[' /etc/pacman.conf | grep -v -e 'options' -e '^#' | tr -d '[]' )
51 available_pkgs=$( for r in $enabled_repos; do echo /var/lib/pacman/sync/$r/*; done )
52 COMPREPLY=( $( compgen -W "$( for i in $available_pkgs; do j=${i##*/}; echo ${j%-*-*}; done )" -- $cur ) )
57 local installed_groups
58 installed_groups=$( find /var/lib/pacman/local -name desc -exec sed -ne '/%GROUPS%/,/^$/{//d; p}' {} \; | sort -u )
59 COMPREPLY=( $( compgen -W "$( for i in $installed_groups; do echo ${i%-*-*}; done )" -- $cur ) )
64 #find balks easilly on a find /foo/*/* type dir, especially one like
66 # This little change-up removes the find *and* only uses enabled repos
67 local available_groups
69 enabled_repos=$( grep '\[' /etc/pacman.conf | grep -v -e 'options' -e '^#' | tr -d '[]' )
70 available_groups=$( for r in $enabled_repos; do sed '/%GROUPS%/,/^$/{//d; p}' /var/lib/pacman/sync/$r/*/desc | sort -u; done )
71 COMPREPLY=( $( compgen -W "$( for i in $available_groups; do echo ${i%-*-*}; done )" -- $cur ) )
80 cur=${COMP_WORDS[COMP_CWORD]}
81 prev=${COMP_WORDS[COMP_CWORD-1]}
94 if [[ "$cur" == -* ]]; then
95 COMPREPLY=( $( compgen -W '\
115 --noprogressbar' -- $cur ) )
120 complete -o default -F _makepkg makepkg
129 if [ $(expr index "${str}" "${c}") -gt 0 ]; then
138 local a arg toparse op mod cur
141 # This argument parsing is done so we can check for flag existance later
142 # right now it's a tad crappy, but does the job
143 for (( i=1; i < ${#COMP_WORDS[@]}-1; i++ )); do
162 verbose) mod="${mod}v" ;;
163 root) mod="${mod}r" ;;
164 dbpath) mod="${mod}b" ;;
165 nodeps) mod="${mod}d" ;;
166 force) mod="${mod}f" ;;
167 groups) mod="${mod}g" ;;
168 info) mod="${mod}i" ;;
169 list) mod="${mod}l" ;;
170 print-uris) mod="${mod}p" ;;
171 search) mod="${mod}s" ;;
172 sysupgrade) mod="${mod}u" ;;
173 upgrades) mod="${mod}u" ;;
174 downloadonly) mod="${mod}w" ;;
175 refresh) mod="${mod}y" ;;
176 changelog) mod="${mod}c" ;;
177 deps) mod="${mod}d" ;;
178 explicit) mod="${mod}e" ;;
179 unrequired) mod="${mod}t" ;;
180 foreign) mod="${mod}m" ;;
181 owns) mod="${mod}o" ;;
182 file) mod="${mod}p" ;;
183 search) mod="${mod}s" ;;
184 upgrades) mod="${mod}u" ;;
185 cascade) mod="${mod}c" ;;
186 dbonly) mod="${mod}k" ;;
187 nosave) mod="${mod}n" ;;
188 recursive) mod="${mod}s" ;;
189 unneeded) mod="${mod}u" ;;
194 arglen=$(( ${#toparse}-1 ))
195 for c in $(seq 0 "${arglen}"); do
197 [ "${arg}" != "-" ] && mod="${mod}${arg}"
201 cur=${COMP_WORDS[COMP_CWORD]}
203 if [ $COMP_CWORD -eq 1 ] && [[ "$cur" == -* ]]; then
204 COMPREPLY=( $( compgen -W '\
216 if [[ "$cur" == -* ]]; then
219 COMPREPLY=( $( compgen -W '\
238 COMPREPLY=( $( compgen -W '\
259 COMPREPLY=( $( compgen -W '\
290 COMPREPLY=( $( compgen -W '\
321 COMPREPLY=( $( compgen -d -- "$cur" ) \
322 $( compgen -f -X '!*.pkg.tar.gz' -- "$cur" ) )
330 if _instring $mod g; then
332 elif _instring $mod o; then
333 COMPREPLY=( $( compgen -d -- "$cur" ) \
334 $( compgen -f -- "$cur" ) )
335 elif _instring $mod p; then
336 COMPREPLY=( $( compgen -d -- "$cur" ) \
337 $( compgen -f -X '!*.pkg.tar.gz' -- "$cur" ) )
338 elif _instring $mod u; then
351 if _instring $mod l; then
363 complete -o filenames -F _pacman pacman