3 ms·
You can also munge the pw-dump output with jq, instead of needing something to be compiled. pw-dump | jq ' ( .[] | select(.
by Arnavion 5y ago
You can also munge the pw-dump output with jq, instead of needing something to be compiled.
pw-dump | jq '
(
.[] |
select(.type == "PipeWire:Interface:Metadata") |
(.metadata // [])[] |
select(.key == "default.audio.sink") |
.value.name
) as $default_sink_node_name |
.[] |
select(.info.props["node.name"] == $default_sink_node_name) as $default_sink_node |
.
'
- smasher164 5y agoYes. This is how I did it initially, before rewriting it using serde. However, as I mention here (https://www.reddit.com/r/swaywm/comments/sks343/comment/hvn3p3c/?utm_source=share&utm_medium=web2x&context=3 https://www.reddit.com/r/swaywm/comments/sks343/comment/hvn3...), shell with jq was too slow -- particularly if you're holding down the volume key.
- Arnavion 5y agoAh, good to know. I didn't think it would be noticeably slow, especially given it still has to spawn `pw-dump` and `pw-cli`. But I guess `pw-dump` outputs so much that speeding up just the JSON munging is still worth it. BTW, you may consider using `Cow<'a, str>` instead of `&'a str` for the deserialized fields. For JSON strings that have escapes, serde can't deserialize them into a `&'a str`, so the whole deserialization will fail. `Cow<'a, str>` still works with `#[serde(borrow)]` in that strings that can be deserialized in-place will be the `Borrowed(&'a str)` variant, and only strings that can't will be `Owned(String)` (there's a special borrow-specific deserializer of Cow inside serde to achieve this).
- faho 5y agojq is surprisingly slow. I've had success calling python to parse some json from a shell script instead of jq.