-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpackage-necessity.nu
executable file
·67 lines (58 loc) · 1.54 KB
/
package-necessity.nu
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#! /usr/bin/env nu
def 'pkg from info get name' [] {
lines
| where {|line| $line | str starts-with 'Name'}
| each {|line| $line | str replace 'Name\s*:\s*' ''}
}
def 'pkg from info get repo' [] {
lines
| where {|line| $line | str starts-with 'Repository'}
| each {|line| $line | str replace 'Repository\s*:\s*' ''}
}
def 'pkg from info get name-repo' [] {
let info = $in
let names = ($info | pkg from info get name)
let repos = ($info | pkg from info get repo)
$names
| zip $repos
| each {|x| [[name repo]; [$x.0 $x.1]]}
| flatten
| group-by name
| transpose name info
| insert repo {|x| $x.info | get repo}
| reject info
}
def load-pkg-name [] {
open init-aur-builder.yaml | get aur-package-names
}
def 'pkg from name get info' [] {
pacman -Si $in
}
def 'pkg from name get repo' [] {
pkg from name get info | pkg from info get name-repo
}
def 'pkg repo is-needed' [repo: list] {
$repo | all {|repo| $repo == 'khai' or $repo == 'aur'}
}
def show-data [] {
load-pkg-name
| pkg from name get repo
| insert needed {|x| pkg repo is-needed $x.repo}
| update repo {|x| $x.repo | str join ', '}
}
def main [command: string] {
if $command == 'all' {
show-data
} else if $command == 'needed' {
show-data | where needed
} else if $command == 'unneeded' {
show-data | where not needed
} else {
let span = (metadata $command).span
error make {
msg: 'Invalid command: Must be either "all", "needed", or "unneeded"'
start: span.start
end: span.end
}
}
}