Skip to content

Instantly share code, notes, and snippets.

@leyyce
Last active October 21, 2025 08:32
Show Gist options
  • Select an option

  • Save leyyce/8ac06eb16bd1b1befdfd75a81dfbe399 to your computer and use it in GitHub Desktop.

Select an option

Save leyyce/8ac06eb16bd1b1befdfd75a81dfbe399 to your computer and use it in GitHub Desktop.
[bash/fish] pacman: List optional dependencies for all installed packages
function list_optional_deps
for pkg in (pacman -Qeq)
set -l deps (pacman -Qi $pkg | awk '
BEGIN {flag=0}
/^Optional Deps/ {
flag=1;
sub(/^[^:]+:[ \t]*/, "");
print;
next
}
/^[^ \t]/ { if(flag==1) exit }
{ if(flag==1) {
sub(/^[ \t]+/, "");
sub(/^:[ \t]*/, "");
print
} }
')
if test (count $deps) -eq 0 -o "$deps[1]" = "None"
continue
end
printf "%sPackage: %s%s\n" (set_color blue) $pkg (set_color normal)
for dep in $deps
set -l pkg_name (string replace -r '^([^: >=<]+).*' '$1' -- $dep)
if pacman -Qq "$pkg_name" >/dev/null 2>&1
printf "%s %s%s\n" (set_color green) $dep (set_color normal)
else
printf "%s %s%s\n" (set_color red) $dep (set_color normal)
end
end
echo
end
end
#!/bin/bash
list_optional_deps() {
local blue="\033[34m"
local green="\033[32m"
local red="\033[31m"
local reset="\033[0m"
for pkg in $(pacman -Qeq); do
local deps=$(pacman -Qi "$pkg" | awk '
BEGIN {flag=0}
/^Optional Deps/ {
flag=1;
sub(/^[^:]+:[ \t]*/, "");
print;
next
}
/^[^ \t]/ { if(flag==1) exit }
{ if(flag==1) {
sub(/^[ \t]+/, "");
sub(/^:[ \t]*/, "");
print
} }
')
if [ -z "$deps" ] || [ "$deps" = "None" ]; then
continue
fi
printf "${blue}Package: %s${reset}\n" "$pkg"
while IFS= read -r dep; do
local pkg_name=$(echo "$dep" | sed -E 's/^([^: >=<]+).*/\1/')
if pacman -Qq "$pkg_name" >/dev/null 2>&1; then
printf "${green} %s${reset}\n" "$dep"
else
printf "${red} %s${reset}\n" "$dep"
fi
done <<< "$deps"
echo
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment