diff options
| author | pml68 <contact@pml68.dev> | 2025-09-03 18:42:44 +0200 |
|---|---|---|
| committer | pml68 <contact@pml68.dev> | 2025-09-03 20:00:18 +0200 |
| commit | 82e1f3835335d143bbbf8cb0378ff36822ea9483 (patch) | |
| tree | 8e55cab2cda1cc42df7c0a4c21392b2d6f4394bf | |
| parent | fix: only run `git diff` when _update has pulled changes (diff) | |
| download | aur-82e1f3835335d143bbbf8cb0378ff36822ea9483.tar.gz | |
feat: add -v/--version option
| -rwxr-xr-x | aur | 180 | ||||
| -rw-r--r-- | shell-completions/aur-completion.bash (renamed from aur-completion.bash) | 6 | ||||
| -rw-r--r-- | shell-completions/aur.completor.bash (renamed from aur.completor.bash) | 3 | ||||
| -rw-r--r-- | shell-completions/aur.fish (renamed from aur.fish) | 3 |
4 files changed, 105 insertions, 87 deletions
@@ -1,96 +1,112 @@ #!/bin/bash +{ + set -eu -set -eu + version=1.0.0 -_help() { - echo "Usage: $(basename "$0") [OPTIONS]" - echo "" - echo "Options:" - echo " <pkg1 pkg2 ...> Download and install/update the specified packages." - echo " -g, --git Updates all packages, including -git packages." - echo " -c, --config <file> Parse the specified config file and install/update" - echo " packages listed in it (one per line)." - echo " -f, --force Reinstall all packages, even if they are up-to-date." - echo " -l, --list List currently installed packages." - echo " -h, --help Display this help text." - echo " [nothing] Check all packages for updates." - echo "" - exit "${1-0}" -} + _help() { + echo "Usage: $(basename "$0") [OPTION]" + echo "" + echo "Provides basic AUR package management functionality, showing users a diff before upgrading a package." + echo "" + echo "Options:" + echo " <pkg1 pkg2 ...> Download and install/update the specified packages." + echo " -g, --git Checks all packages for updates and rebuilds all -git packages." + echo " -c, --config <file> Parse the specified config file and install/update" + echo " packages listed in it (one per line)." + echo " -f, --force Reinstall all packages, even if they are up-to-date." + echo " -l, --list List currently installed packages." + echo " -h, --help Display this help text." + echo " -v, --version Prints program version." + echo " [nothing] Check all packages for updates." + echo "" + exit "${1-0}" + } + + _version() { + echo "aur $version" + exit 0 + } -_update() { - for dir in ~/.aur/*; do - cd "$dir" || continue + _update() { + for dir in ~/.aur/*; do + cd "$dir" || continue - if [[ $(git pull) != "Already up to date." ]]; then - git diff "@{1}.." - read -p "Proceed with installation? [Y/n] " proceed - if [[ -z "$proceed" ]] || [[ "$proceed" == "Y" ]] || [[ "$proceed" == "y" ]]; then + if [[ $(git pull) != "Already up to date." ]]; then + git diff "@{1}.." + read -p "Proceed with installation? [Y/n] " proceed + if [[ -z "$proceed" ]] || [[ "$proceed" == "Y" ]] || [[ "$proceed" == "y" ]]; then + makepkg -si ; _clean + fi + elif [[ "${1-}" == "-f" ]] || [[ "$dir" == *-git && "${1-}" == "-g" ]]; then makepkg -si ; _clean fi - elif [[ "${1-}" == "-f" ]] || [[ "$dir" == *-git && "${1-}" == "-g" ]]; then - makepkg -si ; _clean - fi - done -} + done + } -_clean() { - git clean -ffxd - git restore . -} + _clean() { + git clean -ffxd + git restore . + } -_update_or_install() { - for package in "$@"; do - if cd ~/.aur/"$package"; then - local proceed="" + _update_or_install() { + for package in "$@"; do + if cd ~/.aur/"$package"; then + local proceed="" - if [[ $(git pull) != "Already up to date." ]]; then - git diff "@{1}.." + if [[ $(git pull) != "Already up to date." ]]; then + git diff "@{1}.." + read -p "Proceed with installation? [Y/n] " proceed + fi + + if [[ -z "$proceed" ]] || [[ "$proceed" == "Y" ]] || [[ "$proceed" == "y" ]]; then + makepkg -si ; _clean + fi + else + git clone "https://aur.archlinux.org/$package" ~/.aur/"$package" + cd ~/.aur/"$package" || continue + ${EDITOR:-nvim} PKGBUILD read -p "Proceed with installation? [Y/n] " proceed + if [[ -z "$proceed" ]] || [[ "$proceed" == "Y" ]] || [[ "$proceed" == "y" ]]; then + makepkg -si ; _clean + fi fi + done + } - if [[ -z "$proceed" ]] || [[ "$proceed" == "Y" ]] || [[ "$proceed" == "y" ]]; then - makepkg -si ; _clean - fi - else - git clone "https://aur.archlinux.org/$package" ~/.aur/"$package" - cd ~/.aur/"$package" || continue - ${EDITOR:-nvim} PKGBUILD - read -p "Proceed with installation? [Y/n] " proceed - if [[ -z "$proceed" ]] || [[ "$proceed" == "Y" ]] || [[ "$proceed" == "y" ]]; then - makepkg -si ; _clean - fi - fi - done -} + if [[ -n "${1-}" ]]; then + case "$1" in + --list | -l) + pacman -Qm + ;; + --force | -f) + _update -f + ;; + --config | -c) + packages=$(tr '\n' ' ' < "$2") + _update_or_install "$packages" + ;; + --git | -g) + _update -g + ;; + --help | -h) + _help 0 + ;; + --version | -v) + _version + ;; + -*) + echo "Unknown option: $1" + echo "" + _help 16 + ;; + *) + _update_or_install "$@" + ;; + esac + else + _update + fi -if [[ -n "${1-}" ]]; then - case "$1" in - --list | -l) - pacman -Qm - ;; - --force | -f) - _update -f - ;; - --config | -c) - packages=$(tr '\n' ' ' < "$2") - _update_or_install "$packages" - ;; - --git | -g) - _update -g - ;; - --help | -h) - _help 0 - ;; - -*) - echo "Unknown option: $1" - echo "" - _help 16 - ;; - *) - _update_or_install "$@" - ;; - esac -else - _update -fi + exit +} diff --git a/aur-completion.bash b/shell-completions/aur-completion.bash index 3644e85..224f1ee 100644 --- a/aur-completion.bash +++ b/shell-completions/aur-completion.bash @@ -12,13 +12,13 @@ # shellcheck disable=2207 # editorconfig-checker-disable -_aur_comp_cmd_opts=( -h --help -l --list -f --force -g --git -c --config ) +_aur_comp_cmd_opts=( -h --help -v --version -l --list -f --force -g --git -c --config ) _aur_comp_reply_aur_pkgs () { pkgs=$(basename -a ~/.aur/*/ | paste -d ' ' -s -); - COMPREPLY=("$(compgen -W "$pkgs" -- "$cur")") + COMPREPLY=($(compgen -W "$pkgs" -- "$cur")) } _aur_comp_reply_dirs () @@ -69,7 +69,7 @@ _aur_comp_reply_set() { local IFS=', ' local array_list="" array_name # shellcheck disable=2068 - for array_name in $@; do + for array_name in "$@"; do array_list="$array_list \${_aur_comp_var_${array_name}[*]}" done array_list="${array_list[*]:1}" diff --git a/aur.completor.bash b/shell-completions/aur.completor.bash index 48c6e8b..cb83422 100644 --- a/aur.completor.bash +++ b/shell-completions/aur.completor.bash @@ -4,6 +4,7 @@ cmd=aur cmd_args=@aur_pkgs cmd_opts=( -h --help + -v --version -l --list -f --force -g --git @@ -14,5 +15,5 @@ cmd_opts=( reply_aur_pkgs() { pkgs=$(basename -a ~/.aur/*/ | paste -d ' ' -s -) - COMPREPLY=( "$(compgen -W "$pkgs" -- "$cur")" ) + COMPREPLY=( $(compgen -W "$pkgs" -- "$cur") ) } diff --git a/aur.fish b/shell-completions/aur.fish index fea8e37..ae54b02 100644 --- a/aur.fish +++ b/shell-completions/aur.fish @@ -1,10 +1,11 @@ function _aur_no_switches - not __fish_contains_opt -s h help -s l list -s f force -s g git -s c config + not __fish_contains_opt -s h help -s v version -s l list -s f force -s g git -s c config end complete -c aur -f complete -c aur -n "_aur_no_switches" -a "(basename -a ~/.aur/*/)" complete -c aur -s h -l help +complete -c aur -s v -l version complete -c aur -s l -l list complete -c aur -s f -l force complete -c aur -s g -l git |
