summaryrefslogtreecommitdiff
path: root/pactree-aur
blob: 67716062a5bd7329de445ac28814c1636033513c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/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");
}
'