first upload
This commit is contained in:
+202
@@ -0,0 +1,202 @@
|
||||
#!/usr/bin/env bash
|
||||
# CLI parsing — paru-like short option clusters
|
||||
|
||||
# Globals set by parse_args
|
||||
OP= # S Q R G B P D F T U none interactive
|
||||
OP_REFRESH=0 # y
|
||||
OP_UPGRADE=0 # u
|
||||
OP_SEARCH=0 # s (count)
|
||||
OP_INFO=0 # i
|
||||
OP_CLEAN=0 # c
|
||||
OP_AUR_ONLY=0 # a (with S/Q)
|
||||
OP_PRINT=0 # -p for -G
|
||||
OP_BUILD_INSTALL=0 # -i for -B
|
||||
TARGETS=()
|
||||
PACMAN_EXTRA=() # leftover short flags for pacman passthrough
|
||||
DO_PASSTHRU=0
|
||||
|
||||
print_help() {
|
||||
cat <<'EOF'
|
||||
Usage:
|
||||
miaur
|
||||
miaur <operation> [...]
|
||||
miaur <search terms>
|
||||
|
||||
miaur is a pure-shell AUR helper with paru-like everyday commands.
|
||||
|
||||
Pacman operations extended with AUR support:
|
||||
miaur {-h --help}
|
||||
miaur {-V --version}
|
||||
miaur {-Q --query} [options] [packages]
|
||||
miaur {-R --remove} [options] <packages>
|
||||
miaur {-S --sync} [options] [packages]
|
||||
miaur {-U --upgrade} [options] <files>
|
||||
|
||||
Additional operations:
|
||||
miaur {-G --getpkgbuild} [packages]
|
||||
miaur {-B --build} [directories]
|
||||
|
||||
With no arguments, miaur runs 'miaur -Syu'.
|
||||
|
||||
Common commands:
|
||||
miaur -Syu Upgrade repository and AUR packages
|
||||
miaur -Sua Upgrade AUR packages only
|
||||
miaur -S <package> Install from a repository or the AUR
|
||||
miaur -Ss <query> Search packages
|
||||
miaur -Si <package> Show package information
|
||||
miaur -Qua List available AUR upgrades
|
||||
miaur -G <package> Download a PKGBUILD
|
||||
miaur -Gp <package> Print a PKGBUILD
|
||||
miaur -Bi . Build and install a local PKGBUILD
|
||||
|
||||
Options:
|
||||
-a, --aur Assume targets are from the AUR
|
||||
--repo Assume targets are from repositories
|
||||
--skipreview Skip PKGBUILD review
|
||||
--cleanafter Remove build sources after installation
|
||||
--[no]removemake Remove make dependencies after installation
|
||||
--bottomup Show AUR results first
|
||||
--topdown Show repository results first (default)
|
||||
--clonedir <path> Set the PKGBUILD clone directory
|
||||
--mflags <flags> Pass additional flags to makepkg
|
||||
--sudoloop Keep sudo credentials alive (default)
|
||||
--nosudoloop Disable the sudo keep-alive loop
|
||||
EOF
|
||||
}
|
||||
|
||||
parse_args() {
|
||||
if [[ $# -eq 0 ]]; then
|
||||
OP=S
|
||||
OP_REFRESH=1
|
||||
OP_UPGRADE=1
|
||||
return 0
|
||||
fi
|
||||
|
||||
# No leading dash → interactive search
|
||||
if [[ $1 != -* ]]; then
|
||||
OP=interactive
|
||||
TARGETS=("$@")
|
||||
return 0
|
||||
fi
|
||||
|
||||
local -a raw=("$@")
|
||||
local i=0
|
||||
while ((i < ${#raw[@]})); do
|
||||
local arg=${raw[$i]}
|
||||
case "$arg" in
|
||||
-h | --help)
|
||||
print_help
|
||||
exit 0
|
||||
;;
|
||||
-V | --version)
|
||||
printf 'miaur v%s\n' "$MIAUR_VERSION"
|
||||
exit 0
|
||||
;;
|
||||
--aur)
|
||||
OP_AUR_ONLY=1
|
||||
MIAUR_MODE=aur
|
||||
;;
|
||||
--repo)
|
||||
MIAUR_MODE=repo
|
||||
;;
|
||||
--skipreview) MIAUR_SKIPREVIEW=1 ;;
|
||||
--review) MIAUR_SKIPREVIEW=0 ;;
|
||||
--cleanafter) MIAUR_CLEANAFTER=1 ;;
|
||||
--nocleanafter) MIAUR_CLEANAFTER=0 ;;
|
||||
--removemake) MIAUR_REMOVEMAKE=1 ;;
|
||||
--noremovermake) MIAUR_REMOVEMAKE=0 ;;
|
||||
--bottomup) MIAUR_BOTTOMUP=1 ;;
|
||||
--topdown) MIAUR_BOTTOMUP=0 ;;
|
||||
--sudoloop) MIAUR_SUDOLOOP=1 ;;
|
||||
--nosudoloop) MIAUR_SUDOLOOP=0 ;;
|
||||
--clonedir)
|
||||
i=$((i + 1))
|
||||
MIAUR_CLONEDIR=${raw[$i]:-}
|
||||
[[ -n $MIAUR_CLONEDIR ]] || die "--clonedir requires a path"
|
||||
;;
|
||||
--clonedir=*) MIAUR_CLONEDIR=${arg#*=} ;;
|
||||
--mflags)
|
||||
i=$((i + 1))
|
||||
MIAUR_MFLAGS=${raw[$i]:-}
|
||||
;;
|
||||
--mflags=*) MIAUR_MFLAGS=${arg#*=} ;;
|
||||
--mode)
|
||||
i=$((i + 1))
|
||||
MIAUR_MODE=${raw[$i]:-}
|
||||
;;
|
||||
--mode=*) MIAUR_MODE=${arg#*=} ;;
|
||||
--sync) OP=S ;;
|
||||
--query) OP=Q ;;
|
||||
--remove)
|
||||
OP=R
|
||||
DO_PASSTHRU=1
|
||||
;;
|
||||
--getpkgbuild) OP=G ;;
|
||||
--build) OP=B ;;
|
||||
--database | --files | --deptest | --upgrade)
|
||||
DO_PASSTHRU=1
|
||||
;;
|
||||
--)
|
||||
i=$((i + 1))
|
||||
while ((i < ${#raw[@]})); do
|
||||
TARGETS+=("${raw[$i]}")
|
||||
i=$((i + 1))
|
||||
done
|
||||
break
|
||||
;;
|
||||
-*)
|
||||
local cluster=${arg:1}
|
||||
local j c
|
||||
for ((j = 0; j < ${#cluster}; j++)); do
|
||||
c=${cluster:j:1}
|
||||
case "$c" in
|
||||
S) OP=S ;;
|
||||
Q) OP=Q ;;
|
||||
R)
|
||||
OP=R
|
||||
DO_PASSTHRU=1
|
||||
;;
|
||||
G) OP=G ;;
|
||||
B) OP=B ;;
|
||||
D | F | T | U) DO_PASSTHRU=1 ;;
|
||||
y) OP_REFRESH=1 ;;
|
||||
u) OP_UPGRADE=1 ;;
|
||||
s) OP_SEARCH=$((OP_SEARCH + 1)) ;;
|
||||
i)
|
||||
if [[ $OP == B ]]; then
|
||||
OP_BUILD_INSTALL=1
|
||||
else
|
||||
OP_INFO=1
|
||||
fi
|
||||
;;
|
||||
c) OP_CLEAN=1 ;;
|
||||
a)
|
||||
OP_AUR_ONLY=1
|
||||
MIAUR_MODE=aur
|
||||
;;
|
||||
p)
|
||||
if [[ $OP == G ]]; then
|
||||
OP_PRINT=1
|
||||
else
|
||||
PACMAN_EXTRA+=("$c")
|
||||
fi
|
||||
;;
|
||||
h)
|
||||
print_help
|
||||
exit 0
|
||||
;;
|
||||
V)
|
||||
printf 'miaur v%s\n' "$MIAUR_VERSION"
|
||||
exit 0
|
||||
;;
|
||||
*) PACMAN_EXTRA+=("$c") ;;
|
||||
esac
|
||||
done
|
||||
;;
|
||||
*)
|
||||
TARGETS+=("$arg")
|
||||
;;
|
||||
esac
|
||||
i=$((i + 1))
|
||||
done
|
||||
}
|
||||
Reference in New Issue
Block a user