Last active
October 21, 2025 08:32
-
-
Save leyyce/8ac06eb16bd1b1befdfd75a81dfbe399 to your computer and use it in GitHub Desktop.
[bash/fish] pacman: List optional dependencies for all installed packages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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]*/, ""); | |
| } } | |
| ') | |
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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]*/, ""); | |
| } } | |
| ') | |
| 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