-
-
Save AladW/83ab3f1e5a52b731cd3a38447363f86a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash - | |
readonly argv0=aur | |
readonly lib_dir=${AUR_EXEC_PATH:-'AURUTILS_LIB_DIR'} | |
XDG_CONFIG_HOME=${XDG_CONFIG_HOME:-$HOME/.config} | |
config_file=$XDG_CONFIG_HOME/aurutils/aurutils.conf | |
shopt -s nullglob | |
usage() { | |
printf >&2 'usage: %s [-K] [command]\n\n' "$argv0" | |
printf >&2 'available commands:\n' | |
for p in "$lib_dir"/aur-*; do | |
printf '%q\n' "${p##*/aur-}" | |
done | column >&2 | |
printf >&2 '\navailable user commands:\n' | |
compgen -c aur- | sort -u | while IFS= read -r; do | |
if ! [[ -f $lib_dir/$REPLY ]]; then | |
printf '%q\n' "${REPLY#aur-}" | |
fi | |
done | column >&2 | |
exit 1 | |
} | |
if [[ -z $1 ]]; then | |
usage | |
fi | |
if [[ "$PATH" != "$lib_dir:"* ]]; then | |
readonly PATH=$lib_dir:$PATH | |
fi | |
read_options() { | |
#global options | |
local key value | |
while IFS='=' read -r key value; do | |
if [[ $value ]]; then | |
options+=("$key=$value") | |
else | |
options+=("$key") | |
fi | |
done < <(pacini --section="$2" "$1") | |
} | |
options=() | |
case $1 in | |
-K|--config) # XXX take configuration file as argument | |
shift; | |
if [[ -z $1 ]]; then | |
usage | |
fi | |
if [[ -f $config_file ]]; then | |
case $1 in | |
# aur-sync uses both aur-build and its own specific options | |
sync) | |
if pacini "$config_file" --section-list | grep -q build; then | |
read_options "$config_file" build | |
fi | |
if pacini "$config_file" --section-list | grep -q sync; then | |
read_options "$config_file" sync | |
fi | |
;; | |
# options for other tools | |
*) | |
if pacini "$config_file" --section-list | grep -q "$1"; then | |
read_options "$config_file" "$1" | |
fi | |
;; | |
esac | |
else | |
printf >&2 '%s: no such file or directory\n' "$config_file" | |
exit 1 | |
fi | |
;; | |
*) | |
esac | |
if type -P "aur-$1" >/dev/null; then | |
exec "aur-$1" "${options[@]}" "${@:2}" | |
else | |
printf >&2 '%s: %q is not an aur command\n' "$argv0" "$1" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment