From 82e1f3835335d143bbbf8cb0378ff36822ea9483 Mon Sep 17 00:00:00 2001 From: pml68 Date: Wed, 3 Sep 2025 18:42:44 +0200 Subject: feat: add -v/--version option --- aur | 180 ++++++++++++++++++---------------- aur-completion.bash | 107 -------------------- aur.completor.bash | 18 ---- aur.fish | 11 --- shell-completions/aur-completion.bash | 107 ++++++++++++++++++++ shell-completions/aur.completor.bash | 19 ++++ shell-completions/aur.fish | 12 +++ 7 files changed, 236 insertions(+), 218 deletions(-) delete mode 100644 aur-completion.bash delete mode 100644 aur.completor.bash delete mode 100644 aur.fish create mode 100644 shell-completions/aur-completion.bash create mode 100644 shell-completions/aur.completor.bash create mode 100644 shell-completions/aur.fish diff --git a/aur b/aur index b63568f..9ccf87e 100755 --- a/aur +++ b/aur @@ -1,96 +1,112 @@ #!/bin/bash +{ + set -eu -set -eu + version=1.0.0 -_help() { - echo "Usage: $(basename "$0") [OPTIONS]" - echo "" - echo "Options:" - echo " Download and install/update the specified packages." - echo " -g, --git Updates all packages, including -git packages." - echo " -c, --config 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 " Download and install/update the specified packages." + echo " -g, --git Checks all packages for updates and rebuilds all -git packages." + echo " -c, --config 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/aur-completion.bash deleted file mode 100644 index 3644e85..0000000 --- a/aur-completion.bash +++ /dev/null @@ -1,107 +0,0 @@ -# This file is generated by [bash-completor](https://github.com/adoyle-h/bash-completor/tree/v0.2.0). Do not modify it manually. -# -# [Usage] -# Put "source aur-completion.bash" in your bashrc. -# -# If you want to debug the completion. -# Search '# Uncomment this line for debug' line in this file. -# -# [Update Script] -# bash-completor -c aur.completor.bash - -# shellcheck disable=2207 -# editorconfig-checker-disable - -_aur_comp_cmd_opts=( -h --help -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")") -} - -_aur_comp_reply_dirs () -{ - local IFS=$'\n'; - compopt -o nospace -o filenames; - COMPREPLY=($(compgen -A directory -- "$cur")) -} - -_aur_comp_reply_files () -{ - local IFS=$'\n'; - compopt -o nospace -o filenames; - COMPREPLY=($(compgen -A file -- "$cur")) -} - -_aur_comp_reply_files_in_pattern () -{ - compopt -o nospace -o filenames; - local path; - while read -r path; do - if [[ $path =~ $1 ]] || [[ -d $path ]]; then - COMPREPLY+=("$path"); - fi; - done < <(compgen -A file -- "$cur") -} - -_aur_comp_reply_list () -{ - local IFS=', '; - local array_list="" array_name; - for array_name in "$@"; - do - array_list="$array_list \${${array_name}[*]}"; - done; - array_list="${array_list[*]:1}"; - IFS=$'\n'' '; - eval "COMPREPLY=( \$(compgen -W \"$array_list\" -- \"\$cur\") )" -} - -_aur_comp_reply_words () -{ - local IFS=$'\n'; - COMPREPLY=($(IFS=', ' compgen -W "$*" -- "${cur#=}")) -} - -_aur_comp_reply_set() { - local IFS=', ' - local array_list="" array_name - # shellcheck disable=2068 - for array_name in $@; do - array_list="$array_list \${_aur_comp_var_${array_name}[*]}" - done - array_list="${array_list[*]:1}" - - IFS=$'\n'' ' - eval "COMPREPLY=( \$(compgen -W \"$array_list\" -- \"\$cur\") )" -} - -_aur_completions() { - COMPREPLY=() - local cur=${COMP_WORDS[COMP_CWORD]} - local prev=${COMP_WORDS[COMP_CWORD-1]} - - # Uncomment this line for debug - # echo "[COMP_CWORD:$COMP_CWORD][cur:$cur][prev:$prev][WORD_COUNT:${#COMP_WORDS[*]}][COMP_WORDS:${COMP_WORDS[*]}]" >> bash-debug.log - - # Enter the cmd completion - if [[ ${cur:0:1} == [-+] ]]; then - # rely options of command - _aur_comp_reply_list _aur_comp_cmd_opts - elif [[ ${prev:0:1} == [-+] ]]; then - case "${prev}" in - # rely the value of command option - -c) _aur_comp_reply_files ;; - --config) _aur_comp_reply_files ;; - *) _aur_comp_reply_aur_pkgs ;; - esac - else - # rely the argument of command - _aur_comp_reply_aur_pkgs - fi -} - -complete -F _aur_completions -o bashdefault aur -# vi: sw=2 ts=2 diff --git a/aur.completor.bash b/aur.completor.bash deleted file mode 100644 index 48c6e8b..0000000 --- a/aur.completor.bash +++ /dev/null @@ -1,18 +0,0 @@ -# shellcheck disable=SC2034 -output=aur-completion.bash -cmd=aur -cmd_args=@aur_pkgs -cmd_opts=( - -h --help - -l --list - -f --force - -g --git - -c:@files - --config:@files -) - -reply_aur_pkgs() { - pkgs=$(basename -a ~/.aur/*/ | paste -d ' ' -s -) - - COMPREPLY=( "$(compgen -W "$pkgs" -- "$cur")" ) -} diff --git a/aur.fish b/aur.fish deleted file mode 100644 index fea8e37..0000000 --- a/aur.fish +++ /dev/null @@ -1,11 +0,0 @@ -function _aur_no_switches - not __fish_contains_opt -s h help -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 l -l list -complete -c aur -s f -l force -complete -c aur -s g -l git -complete -c aur -s c -l config -F -r diff --git a/shell-completions/aur-completion.bash b/shell-completions/aur-completion.bash new file mode 100644 index 0000000..224f1ee --- /dev/null +++ b/shell-completions/aur-completion.bash @@ -0,0 +1,107 @@ +# This file is generated by [bash-completor](https://github.com/adoyle-h/bash-completor/tree/v0.2.0). Do not modify it manually. +# +# [Usage] +# Put "source aur-completion.bash" in your bashrc. +# +# If you want to debug the completion. +# Search '# Uncomment this line for debug' line in this file. +# +# [Update Script] +# bash-completor -c aur.completor.bash + +# shellcheck disable=2207 +# editorconfig-checker-disable + +_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")) +} + +_aur_comp_reply_dirs () +{ + local IFS=$'\n'; + compopt -o nospace -o filenames; + COMPREPLY=($(compgen -A directory -- "$cur")) +} + +_aur_comp_reply_files () +{ + local IFS=$'\n'; + compopt -o nospace -o filenames; + COMPREPLY=($(compgen -A file -- "$cur")) +} + +_aur_comp_reply_files_in_pattern () +{ + compopt -o nospace -o filenames; + local path; + while read -r path; do + if [[ $path =~ $1 ]] || [[ -d $path ]]; then + COMPREPLY+=("$path"); + fi; + done < <(compgen -A file -- "$cur") +} + +_aur_comp_reply_list () +{ + local IFS=', '; + local array_list="" array_name; + for array_name in "$@"; + do + array_list="$array_list \${${array_name}[*]}"; + done; + array_list="${array_list[*]:1}"; + IFS=$'\n'' '; + eval "COMPREPLY=( \$(compgen -W \"$array_list\" -- \"\$cur\") )" +} + +_aur_comp_reply_words () +{ + local IFS=$'\n'; + COMPREPLY=($(IFS=', ' compgen -W "$*" -- "${cur#=}")) +} + +_aur_comp_reply_set() { + local IFS=', ' + local array_list="" array_name + # shellcheck disable=2068 + for array_name in "$@"; do + array_list="$array_list \${_aur_comp_var_${array_name}[*]}" + done + array_list="${array_list[*]:1}" + + IFS=$'\n'' ' + eval "COMPREPLY=( \$(compgen -W \"$array_list\" -- \"\$cur\") )" +} + +_aur_completions() { + COMPREPLY=() + local cur=${COMP_WORDS[COMP_CWORD]} + local prev=${COMP_WORDS[COMP_CWORD-1]} + + # Uncomment this line for debug + # echo "[COMP_CWORD:$COMP_CWORD][cur:$cur][prev:$prev][WORD_COUNT:${#COMP_WORDS[*]}][COMP_WORDS:${COMP_WORDS[*]}]" >> bash-debug.log + + # Enter the cmd completion + if [[ ${cur:0:1} == [-+] ]]; then + # rely options of command + _aur_comp_reply_list _aur_comp_cmd_opts + elif [[ ${prev:0:1} == [-+] ]]; then + case "${prev}" in + # rely the value of command option + -c) _aur_comp_reply_files ;; + --config) _aur_comp_reply_files ;; + *) _aur_comp_reply_aur_pkgs ;; + esac + else + # rely the argument of command + _aur_comp_reply_aur_pkgs + fi +} + +complete -F _aur_completions -o bashdefault aur +# vi: sw=2 ts=2 diff --git a/shell-completions/aur.completor.bash b/shell-completions/aur.completor.bash new file mode 100644 index 0000000..cb83422 --- /dev/null +++ b/shell-completions/aur.completor.bash @@ -0,0 +1,19 @@ +# shellcheck disable=SC2034 +output=aur-completion.bash +cmd=aur +cmd_args=@aur_pkgs +cmd_opts=( + -h --help + -v --version + -l --list + -f --force + -g --git + -c:@files + --config:@files +) + +reply_aur_pkgs() { + pkgs=$(basename -a ~/.aur/*/ | paste -d ' ' -s -) + + COMPREPLY=( $(compgen -W "$pkgs" -- "$cur") ) +} diff --git a/shell-completions/aur.fish b/shell-completions/aur.fish new file mode 100644 index 0000000..ae54b02 --- /dev/null +++ b/shell-completions/aur.fish @@ -0,0 +1,12 @@ +function _aur_no_switches + 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 +complete -c aur -s c -l config -F -r -- cgit v1.2.3