#!/bin/sh # Runs pactree and outputs the annotated output pactree "$@" | gawk -e ' BEGIN { FS = "[/ ]"; cmd = "pacman -Ss"; while (cmd | getline) { # package name -> repo if (/^[^ ]/) packages[$2] = $1; } } # Appends repo to each package (match each package name and prepend repo) { # misunderstood output of pactree. It has only one package per line. packages_per_line = 1; # Include ";" so it is easier to recognize colors count = split($0, pkgs, /[^;A-Za-z0-9@._+-]+/, seps); for (i = 1; i <= count; i++) { pkg = pkgs[i]; if (match(pkg, /^[0-9;]*m/) > 0) { printf("%s", substr(pkg, 1, RLENGTH)); #printf("(%s:%s)", substr(pkg, 1, RLENGTH), substr(pkg, RLENGTH + 1)); pkg = substr(pkg, RLENGTH + 1); } if (pkg ~ /^[A-Za-z0-9]/ && packages_per_line-- > 0) { if (pkg in packages) { pkg = packages[pkg] "/" pkg; } else { pkg = "aur/" pkg; } } printf("%s", pkg); printf("%s", seps[i]); # Empty for last field } printf("\n"); } '