Improve safety and CLI fidelity for everyday use
Drop default --noconfirm (opt-in via --noconfirm), fix --noremovemake, forward pacman argv intact for -R/-D/-F/-T/-U, deepen PKGBUILD review, show an install plan before building, and add shellcheck CI plus unit tests. Co-authored-by: Frank Vitrano <WHC2006@users.noreply.github.com>
This commit is contained in:
co-authored by
Frank Vitrano
parent
d0f2cfe335
commit
bba71040d6
+70
-15
@@ -1,7 +1,37 @@
|
||||
#!/usr/bin/env bash
|
||||
# PKGBUILD review
|
||||
|
||||
# Review PKGBUILD in dir. Returns 0 to continue, 1 to abort.
|
||||
# Show a file with bat/less/cat
|
||||
_review_show_file() {
|
||||
local file=$1
|
||||
[[ -f $file ]] || return 0
|
||||
msg2 "File: ${file#"$2"/}"
|
||||
if command -v "${MIAUR_BAT}" >/dev/null 2>&1; then
|
||||
"${MIAUR_BAT}" --style=plain --paging=always --language=bash "$file" || true
|
||||
elif command -v less >/dev/null 2>&1; then
|
||||
less -R "$file" || true
|
||||
else
|
||||
cat "$file"
|
||||
fi
|
||||
}
|
||||
|
||||
# List reviewable files in a package directory (relative paths)
|
||||
_review_list_files() {
|
||||
local dir=$1
|
||||
(
|
||||
cd "$dir" || exit 1
|
||||
# PKGBUILD first, then install scripts and other shell helpers
|
||||
[[ -f PKGBUILD ]] && printf '%s\n' PKGBUILD
|
||||
find . -maxdepth 1 -type f \( \
|
||||
-name '*.install' -o \
|
||||
-name '*.sh' -o \
|
||||
-name 'apply-patches' -o \
|
||||
-name '*.hook' \
|
||||
\) ! -name 'PKGBUILD' -printf '%P\n' 2>/dev/null | sort
|
||||
)
|
||||
}
|
||||
|
||||
# Review PKGBUILD in dir. Returns 0 to continue, 1 to abort, 2 to skip.
|
||||
review_pkgbuild() {
|
||||
local dir=$1
|
||||
local name=${2:-$(basename "$dir")}
|
||||
@@ -11,23 +41,17 @@ review_pkgbuild() {
|
||||
local pb="$dir/PKGBUILD"
|
||||
[[ -f $pb ]] || die "PKGBUILD not found: $dir"
|
||||
|
||||
msg "Reviewing the PKGBUILD for $name"
|
||||
if command -v "${MIAUR_BAT}" >/dev/null 2>&1; then
|
||||
"${MIAUR_BAT}" --style=plain --paging=always --language=bash "$pb" || true
|
||||
elif command -v less >/dev/null 2>&1; then
|
||||
less -R "$pb" || true
|
||||
else
|
||||
cat "$pb"
|
||||
msg "Reviewing $name"
|
||||
local -a files=()
|
||||
mapfile -t files < <(_review_list_files "$dir")
|
||||
if [[ ${#files[@]} -gt 1 ]]; then
|
||||
msg2 "Files: ${files[*]}"
|
||||
fi
|
||||
|
||||
# Also show install script / other files briefly
|
||||
local f
|
||||
for f in "$dir"/*.install "$dir"/PKGBUILD; do
|
||||
[[ -f $f ]] || continue
|
||||
done
|
||||
_review_show_file "$pb" "$dir"
|
||||
|
||||
while true; do
|
||||
printf '%s::%s View diff (d), edit (e), continue (y), skip (s), or quit (q)? [Y/d/e/s/q] ' \
|
||||
printf '%s::%s View diff (d), files (f), edit (e), continue (y), skip (s), or quit (q)? [Y/d/f/e/s/q] ' \
|
||||
"${C_BOLD}${C_BLUE}" "${C_RESET}"
|
||||
local ans=
|
||||
read -r ans || return 1
|
||||
@@ -42,9 +66,40 @@ review_pkgbuild() {
|
||||
e | edit)
|
||||
"${MIAUR_EDITOR}" "$pb"
|
||||
;;
|
||||
f | files)
|
||||
local -a again=()
|
||||
mapfile -t again < <(_review_list_files "$dir")
|
||||
local i
|
||||
for i in "${!again[@]}"; do
|
||||
printf ' %s%2d%s %s\n' "${C_DIM}" "$((i + 1))" "${C_RESET}" "${again[$i]}"
|
||||
done
|
||||
printf '%s::%s Open file number (empty to return): ' \
|
||||
"${C_BOLD}${C_BLUE}" "${C_RESET}"
|
||||
local pick=
|
||||
read -r pick || true
|
||||
if [[ $pick =~ ^[0-9]+$ ]]; then
|
||||
local idx=$((pick - 1))
|
||||
if ((idx >= 0 && idx < ${#again[@]})); then
|
||||
_review_show_file "$dir/${again[$idx]}" "$dir"
|
||||
else
|
||||
warn "Invalid number: $pick"
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
d | diff)
|
||||
if [[ -d $dir/.git ]]; then
|
||||
(cd "$dir" && ${MIAUR_GIT} diff -- PKGBUILD) || true
|
||||
(
|
||||
cd "$dir" || exit 0
|
||||
# Prefer unstaged/staged local edits; fall back to last fetch range
|
||||
if ! ${MIAUR_GIT} diff --stat --quiet HEAD 2>/dev/null; then
|
||||
${MIAUR_GIT} --no-pager diff -- HEAD
|
||||
elif ${MIAUR_GIT} rev-parse --verify 'HEAD@{1}' >/dev/null 2>&1; then
|
||||
${MIAUR_GIT} --no-pager diff -- 'HEAD@{1}'..HEAD
|
||||
else
|
||||
warn "No prior revision available for comparison"
|
||||
${MIAUR_GIT} --no-pager diff -- PKGBUILD || true
|
||||
fi
|
||||
) || true
|
||||
else
|
||||
warn "No Git history is available for comparison"
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user