Fastfetch is pretty cool, but it only shows the total ammount of packages for "system" package managers...
So I decided to write this nushell script. Never done much with nushell before. It's... interesting, and fast, but there are plenty of "wtfs" I guess I was not expecting. I'm happy with the result though.
Anyway, this script provides counters for other package/version managers I'm currently using.
So far it only supports
But it's pretty easy to add more.
#!/usr/bin/env nu
# Must be negative
const ERROR_ID = -1
def main [--show-erred(-e) --show-zeroes(-z)] {[
# conlumn names
[ id, count ];
# rows
[ asdf, {asdfc} ]
[ npm, {npmc false} ]
[ npm-all, {npmc true} ]
[ uv, {uvc} ]
] | par-each {
update count { |pkg|
try {
do $pkg.count
} catch {
$ERROR_ID
}
}
} | where { |pkg| (
$show_erred and $pkg.count == $ERROR_ID or
$show_zeroes and $pkg.count == 0 or
$pkg.count > 0
)} | each {
let c: string = if $in.count == $ERROR_ID {
'[error]'
} else {
$in.count | into string
}
$"($c) \(($in.id)\)"
} | str join ', '
}
def asdfc [] {
# Using GNU awk to count the number of lines that start with 2 spaces
# (I prefer gawk to sed, sorry)
asdf list | gawk '/\W\W.+/ {c++} END {print c}' | into int
}
def npmc [deps: bool] {
# npm returns an extra line at the top that we don't want
(npm list (if $deps {'-agp'} else {'-gp'}) | wc -l | into int) - 1
}
def uvc [] {
# uv *seems* to return 2 lines for each package
(uv tool list | wc -l | into int) // 2
}Note: par-each makes execution time considerably faster...
Then I had to add it to .config/fastfetch/config.jsonc:
{ "$schema": "https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json", "modules": [ // ... "packages", { "type": "command", "text": "count-custom-packages", "key": "Packages (Custom)" }, // ... ] }