Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

51 lines (42 sloc) 2.423 kB
#!/bin/bash
# the path to this file should be /etc/bash_completion.d/pacaur
# to use it without reloading your shell: $ source /etc/bash_completion.d/pacaur
_pacaur()
{
# nullglob avoids problems when no results are found (copied from cower's autocomplete)
[[ -o nullglob ]] || { shopt -s nullglob; ng=1; }
# define variables
local cur prev operations options
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
# operations that wrap pacman operations are not completed yet: -S, -Ss, -Si, -Sii, -Sw. -Su, -Qu, -Sc, -Scc
operations="-s --search -i --info -d --download -m --makepkg -y --sync -k --check -u --update -v --version -h --help --fixbackend"
options="-f --force -e --edit -q --quiet -c --clean -a --aur -r --repo --devel --ignore --noconfirm --noedit --rebuild --asroot --carch"
# define a function that checks whether the whole line contains one of the words passed to it
searchfor() { echo "${COMP_LINE}" | grep -q -- "$(echo "$1" | sed 's/ /\\\|/g')"; }
## completion of operations and options
# complete operations when only 'pacaur -' is given
if [[ "${prev}" == "pacaur" ]]; then
COMPREPLY=( $(compgen -W "${operations}" -- $cur) )
# complete options after '-' when an operation is already given
elif [[ "${cur}" == -* ]] && searchfor "${operations}" ; then
COMPREPLY=( $(compgen -W "${options}" -- $cur) )
## completion of package names
# there is no package name completing for -h --help, -v --version
# complete with all packages installed on the system, just after --ignore
elif [[ "${prev}" = --ignore ]]; then
COMPREPLY=( $(compgen -W "$(pacman -Qq)" -- $cur) )
# complete with all locally installed packages, after -k --check -u --update
elif searchfor "-k --check -u --update"; then
COMPREPLY=( $(compgen -W "$(pacman -Qqm)" -- $cur) )
# complete with all available AUR packages, after -s --search -i --info -d --download -m --makepkg -y --sync
# anything shorter than 2 characters can't be autocompleted due to the AUR's search minimum
elif searchfor "-s --search -i --info -d --download -m --makepkg -y --sync"; then
COMPREPLY=( $(compgen -W "$(cower -sq -- ^$cur 2>/dev/null)" -- $cur) )
fi
# restore nullglob setting
[[ $ng ]] && shopt -u nullglob
}
complete -F _pacaur pacaur
# vim:set ts=4 sw=2 et:
Jump to Line
Something went wrong with that request. Please try again.