Merge pull request #1041 from AladW/depends.pl
[aurutils.git] / aur.in
blob87cdedebb8e481fe69c5127540f547ab03fb73a7
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 ! [[ -x $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 "$AUR_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 --exec-path)
47 printf '%s\n' "$lib_dir"
48 exit 0 ;;
49 esac
51 if [[ "$PATH" != "$lib_dir:"* ]]; then
52 readonly PATH=$lib_dir:$PATH
55 if type -P "aur-$1" >/dev/null; then
56 exec "aur-$1" "${@:2}"
57 else
58 printf >&2 '%s: %q is not an aur command\n' "$argv0" "$1"
59 exit 1