Without “| xargs -n 1 basename” would change the output stream to absolute path. With that in mind:
function cargo-registry
argparse 'a/all' 'q/query=' -- $argv
or return
set -l q ""
if set -q _flag_query
set q "$_flag_query"
else
set q "$argv[1]"
end
set -l r \
~/.cargo/registry/src/index.crates.io-*/
set -l dirs
if set -q _flag_all
set dirs (ls -d $r*/ 2>/dev/null)
else
set dirs (
ls -d $r*/ 2>/dev/null \
| xargs -n 1 basename
)
end
if test -z "$q"
printf '%s\n' $dirs \
| sort
else
printf '%s\n' $dirs \
| grep -i "$q" \
| sort
end
end
Results:
~ main
❯ cargo-registry | head -5
ab_glyph_rasterizer-0.1.9
ab_glyph-0.2.31
accesskit_consumer-0.28.0
accesskit_macos-0.20.0
accesskit_winit-0.27.0
~ main
❯ cargo-registry -a | head -5
/Users/jarkko/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/ab_glyph_rasterizer-0.1.9/
/Users/jarkko/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/ab_glyph-0.2.31/
/Users/jarkko/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/accesskit_consumer-0.28.0/
/Users/jarkko/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/accesskit_macos-0.20.0/
/Users/jarkko/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/accesskit_winit-0.27.0/
~ main
❯ cargo-registry egui
egui_glow-0.32.0
egui-0.32.0
egui-wgpu-0.32.0
egui-winit-0.32.0
~ main
❯ cargo-registry egui -a
/Users/jarkko/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/egui_glow-0.32.0/
/Users/jarkko/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/egui-0.32.0/
/Users/jarkko/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/egui-wgpu-0.32.0/
/Users/jarkko/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/egui-winit-0.32.0/
This is a fish function:
function cargo-registry --argument-names query
set -l r \
~/.cargo/registry/src/index.crates.io-*/
set -l c (
ls -d $r*/ 2>/dev/null \
| xargs -n 1 basename
)
if test -z "$query"
printf '%s\n' $c \
| sort
else
printf '%s\n' $c \
| grep -i "$query" \
| sort
end
end
And what it does is:
❯ cargo-registry|head
ab_glyph_rasterizer-0.1.9
ab_glyph-0.2.31
accesskit_consumer-0.28.0
accesskit_macos-0.20.0
accesskit_winit-0.27.0
accesskit-0.19.0
adler2-2.0.1
adler2-2.0.1
ahash-0.8.12
ahash-0.8.12
aho-corasick-1.1.3
allocator-api2-0.2.21
allocator-api2-0.2.21
anstream-0.6.19
anstream-0.6.19
anstyle-1.0.11
anstyle-1.0.11
anstyle-parse-0.2.7
anstyle-parse-0.2.7
anstyle-query-1.1.3
# ...
And also:
❯ cargo-registry egui
egui_glow-0.32.0
egui-0.32.0
egui-wgpu-0.32.0
egui-winit-0.32.0
This is as done as lsiommu can ever be, or at least as far as I’m concerned so it’s a release time:
https://github.com/puavo-org/lsiommu/releases/tag/1.0.0
I.e. I spent last night making it do less from the almost nothing it was doing already ;-) That’s the point of these tools…
That enumerated to:
This sums up to zero mallocs from the main application (while libudev probably does bunch of them when not compiled with make DISCOVER=sysfs).
Motivation to do was this shitty python script:
#!/usr/bin/env python3
#
# Copyright (c) 2022-2023 Jarkko Sakkinen <jarkko.sakkinen@iki.fi>
import os
import sys
IOMMU_SYSFS = '/sys/kernel/iommu_groups'
IOMMU_GROUP_MAX = 128 # an arbitrary choice
def get_iommu_devices():
groups = [None for group in range(IOMMU_GROUP_MAX)]
with os.scandir(IOMMU_SYSFS) as group_it:
for group in group_it:
devices = []
group_sysfs = IOMMU_SYSFS + '/' + group.name + '/devices'
with os.scandir(group_sysfs) as device_it:
for device in device_it:
devices.append(device.name)
index = int(group.name)
if index >= IOMMU_GROUP_MAX:
print('Overflow')
sys.exit(1)
groups[index] = devices
return groups
if __name__ == "__main__":
groups = get_iommu_devices()
for i in range(len(groups)):
group = groups[i]
if group == None:
break
print('IOMMU Group %d' % (i))
group.sort()
for device in group:
# FIXME: Replace with pure Python code:
os.system('lspci -nns ' + device)