Merge pull request #1016 from VorpalBlade/feature/3rd-party-completion
[aurutils.git] / aur.in
blob065bfeff2d10ad7d347ecfda018dcaf784ecae8e
1 #!/bin/bash -
2 readonly XDG_CONFIG_HOME=${XDG_CONFIG_HOME:-$HOME/.config}
3 readonly argv0=aur
4 readonly aur_version='AURUTILS_VERSION'
5 readonly lib_dir=${AUR_EXEC_PATH:-'AURUTILS_LIB_DIR'}
6 shopt -s nullglob
8 if [[ -z $1 ]]; then
9 printf >&2 'usage: %s [command]\n\n' "$argv0"
10 printf >&2 'available commands:\n'
12 for p in "$lib_dir"/aur-*; do
13 printf '%q\n' "${p##*/aur-}"
14 done | column >&2
16 printf >&2 '\navailable user commands:\n'
18 compgen -c aur- | sort -u | while IFS= read -r; do
19 if ! [[ -f $lib_dir/$REPLY ]]; then
20 printf '%q\n' "${REPLY#aur-}"
22 done | column >&2
24 exit 1
27 # load environment
28 if [[ -f ${AUR_ENV=$XDG_CONFIG_HOME/aurutils/env} ]]; then
29 while IFS=' = ' read -r key value; do
30 case $key in
31 AUR*) printf -v "$key" '%s' "$value"
32 export "${key?}" ;;
33 esac
34 done < <(pacini "$XDG_CONFIG_HOME/aurutils/env")
36 wait "$!"
39 case $1 in
40 --version)
41 printf >&2 'aur version %s\n' "$aur_version"
42 exit 0 ;;
43 --env)
44 printenv | grep -E '^AUR' | sort >&2
45 exit 0 ;;
46 esac
48 if [[ "$PATH" != "$lib_dir:"* ]]; then
49 readonly PATH=$lib_dir:$PATH
52 if type -P "aur-$1" >/dev/null; then
53 exec "aur-$1" "${@:2}"
54 else
55 printf >&2 '%s: %q is not an aur command\n' "$argv0" "$1"
56 exit 1