Skip to content

Instantly share code, notes, and snippets.

@y-ack
Created May 1, 2026 18:27
Show Gist options
  • Select an option

  • Save y-ack/30394cd20268268f62054b7dcf824778 to your computer and use it in GitHub Desktop.

Select an option

Save y-ack/30394cd20268268f62054b7dcf824778 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Show a summary of available Arch package upgrades with homepages.
# Usage: upgrade-summary.sh [--aur]
# --aur Also check AUR packages (requires aura)
set -euo pipefail
USE_AUR=0
for arg in "$@"; do
[[ "$arg" == "--aur" ]] && USE_AUR=1
done
get_upgrades() {
pacman -Qu 2>/dev/null || true
if [[ $USE_AUR -eq 1 ]]; then
aura -Qu 2>/dev/null || true
fi
}
upgrades=$(get_upgrades)
if [[ -z "$upgrades" ]]; then
echo "No upgrades available."
exit 0
fi
count=$(echo "$upgrades" | wc -l)
echo "=== Arch package upgrades available: $count ==="
echo
# Build set of explicitly installed packages
declare -A explicit_set
while IFS= read -r pkg; do explicit_set["$pkg"]=1; done < <(pacman -Qe | awk '{print $1}')
# Single batched pacman -Si for all packages; build pkg->url map
mapfile -t pkgs < <(awk '{print $1}' <<< "$upgrades")
declare -A url_map
cur_pkg=
while IFS= read -r line; do
[[ $line == Name* ]] && { cur_pkg="${line##*: }"; cur_pkg="${cur_pkg// /}"; continue; }
[[ $line == URL* ]] && [[ -n $cur_pkg ]] && url_map["$cur_pkg"]="${line##*: }"
done < <(pacman -Si "${pkgs[@]}" 2>/dev/null)
if [[ $USE_AUR -eq 1 ]]; then
for pkg in "${pkgs[@]}"; do
[[ -z "${url_map[$pkg]:-}" ]] && url_map["$pkg"]="https://aur.archlinux.org/packages/$pkg"
done
fi
# Column widths (dynamic)
max_pkg=4; max_old=7; max_new=9
while IFS= read -r line; do
pkg="${line%% *}"; rest="${line#* }"; old="${rest%% ->*}"; new="${rest##*-> }"
(( ${#pkg} > max_pkg )) && max_pkg=${#pkg}
(( ${#old} > max_old )) && max_old=${#old}
(( ${#new} > max_new )) && max_new=${#new}
done <<< "$upgrades"
print_header() {
printf "%-${max_pkg}s %-${max_old}s %-${max_new}s %s\n" "Package" "Current" "Available" "Homepage"
printf "%-${max_pkg}s %-${max_old}s %-${max_new}s %s\n" \
"$(printf '%*s' $max_pkg '' | tr ' ' '-')" \
"$(printf '%*s' $max_old '' | tr ' ' '-')" \
"$(printf '%*s' $max_new '' | tr ' ' '-')" \
"--------"
}
print_group() {
local filter="$1" # "explicit" or "dep"
local found=0
while IFS= read -r line; do
pkg="${line%% *}"; rest="${line#* }"; old="${rest%% ->*}"; new="${rest##*-> }"
local is_explicit=${explicit_set[$pkg]:-0}
[[ $filter == explicit && $is_explicit != 1 ]] && continue
[[ $filter == dep && $is_explicit == 1 ]] && continue
(( found++ == 0 )) && print_header
printf "%-${max_pkg}s %-${max_old}s %-${max_new}s %s\n" "$pkg" "$old" "$new" "${url_map[$pkg]:-<unknown>}"
done <<< "$upgrades"
(( found == 0 )) && echo " (none)" || true
}
n_explicit=0; n_dep=0
while IFS= read -r line; do
pkg="${line%% *}"
[[ ${explicit_set[$pkg]:-0} == 1 ]] && (( ++n_explicit, 1 )) || (( ++n_dep, 1 ))
done <<< "$upgrades"
echo "--- Explicitly installed ($n_explicit) ---"
print_group explicit
echo
echo "--- Dependencies ($n_dep) ---"
print_group dep
echo
echo "Run 'aura -Syu' to apply all upgrades."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment