diff options
| author | pml68 <contact@pml68.dev> | 2024-12-21 11:19:11 +0100 |
|---|---|---|
| committer | pml68 <contact@pml68.dev> | 2024-12-21 11:19:11 +0100 |
| commit | 55fc35e62ef330b3c8722a50361b9c62dbba181f (patch) | |
| tree | f89b70c6874db6779248230ff9ea5d22f06c9813 | |
| download | aur-55fc35e62ef330b3c8722a50361b9c62dbba181f.tar.gz | |
feat: initial commit
| -rw-r--r-- | README.md | 12 | ||||
| -rwxr-xr-x | aur | 60 | ||||
| -rw-r--r-- | aur-completion.bash | 111 | ||||
| -rw-r--r-- | aur.completor.bash | 21 |
4 files changed, 204 insertions, 0 deletions
diff --git a/README.md b/README.md new file mode 100644 index 0000000..7363694 --- /dev/null +++ b/README.md @@ -0,0 +1,12 @@ +# aur + +My AUR helper. See `aur -h` + +## Bash completion + +```sh +cp aur-completion.bash ~/.aur-completion.bash + +# add this line to your .bashrc +source ~/.aur-completion.bash +``` @@ -0,0 +1,60 @@ +#!/bin/sh + +_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" +} + +_update() { + for dir in $(ls -d ~/.aur/*); do + if [[ $(cd $dir && git pull) != "Already up to date." ]] || [[ $1 == "-f" ]] || [[ $dir == *-git && $1 == "-g" ]]; then + (cd $dir && makepkg -si) + fi + done +} + +_clean() { + git clean -ffxd + git restore . +} + +_update_or_install() { + for package in "$@"; do + cd ~/.aur/$package + if [[ $? -eq 0 ]]; then + (git pull && makepkg -si ; _clean) + else + (git clone https://aur.archlinux.org/$package ~/.aur/$package && cd ~/.aur/$package && makepkg -si ; _clean) + fi + done +} + +if [[ -n $1 ]]; then + if [[ $1 == "--list" ]] || [[ $1 == "-l" ]]; then + pacman -Qm + elif [[ $1 == "--force" ]] || [[ $1 == "-f" ]]; then + (_update -f ; _clean) + elif [[ $1 == "--config" ]] || [[ $1 == "-c" ]]; then + packages=`cat $2 | tr '\n' ' '` + aur $packages + elif [[ $1 == "--git" ]] || [[ $1 == "-g" ]]; then + (_update -g ; _clean) + elif [[ $1 == "-h" ]] || [[ $1 == "--help" ]]; then + _help 0 + else + _update_or_install "$@" + fi +else + (_update ; _clean) +fi diff --git a/aur-completion.bash b/aur-completion.bash new file mode 100644 index 0000000..f8938f9 --- /dev/null +++ b/aur-completion.bash @@ -0,0 +1,111 @@ +# 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=($(find ~/.aur/ -type d -mindepth 1 -maxdepth 1)); + for i in "${!pkgs[@]}"; + do + pkgs[$i]=$(basename "${pkgs[$i]}"); + done; + 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 new file mode 100644 index 0000000..28117f4 --- /dev/null +++ b/aur.completor.bash @@ -0,0 +1,21 @@ +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=( $(find ~/.aur/ -type d -mindepth 1 -maxdepth 1) ); + for i in "${!pkgs[@]}"; + do + pkgs[$i]=$(basename "${pkgs[$i]}"); + done; + + COMPREPLY=( $(compgen -W "${pkgs[*]}" -- "$cur") ) +} |
