> supports the DNS-over-TLS and DNS-over-HTTPS protocols, and can emit JSON
This shows how much our old-school Unix tools need an update.
What if all the CLI tools had an option for JSON output and the shell natively supported a query language like `jq`. Then you could pipe commands together:
This assumes the default output would still be the legacy text format. But if the default output changed to JSON then you could get rid of the ugly json-in/out syntax.
I think a better way to handle your approach would be to attempt to make it automatic; for example, if a program could detect its output as "not a TTY" and then (somehow) make an intelligent determination about what kind of object to pass (i.e. if there was a way for the program on the other end of the pipe to say "Send me object data if you want!") then it would be useful, coupled with programs or commandlets to do filtering.
Having to manually specify "you, output JSON! And you, input JSON! and also filter based on this difficult to remember for most people syntax!" would be cumbersome; much easier to have "commandlets" built into the shell to handle this sort of thing in a sort of composable pipeline. For example:
As others have said, Powershell supports this, and it's completely awesome to work with. The fact that (assuming proper metadata on the binaries) I can do queries like this is awesome:
This lets you, for example, have multiple versions of something installed, and have a script easily and cleanly get a list of all of them and either choose which one to use, or run something on each (e.g. for testing scripts).
There are also a lot of "that's weird but handy" features, like being able to interact with environment variables the same way you do local files:
if (Test-Path 'env:GIT_COMMIT') {
echo "GIT_COMMIT is $Env:GIT_COMMIT"
$commit_hash = $Env:GIT_COMMIT
}
Extremely impressed with Microsoft on this implementation. Also worth noting: you can install Powershell on your Linux or macOS systems and use it there as well. Semi-tempted to try implementing things in Powershell as the only cross-platform shell available.
Like probably dozens of others, I've been idly dreaming about reimplementing coreutils / textutils etc to be able to emit and consume structured records in some serialization format.
The thing that would make this really useful is a(t least one) global database of serialization formats to be a lingua franca between tools. Designing those formats to be useful cross-platform would be tough, but you could start with a format db that only promises linux compat, and later add bsd, and maybe windows even later.
edit: google had something like this internally, the "protodb", a versioned repository of protobuf definitions so that any other tool could consume your tool's output.
Some shells, such as elvish [0], nushell [1], mash [2], and even Windows' powershell do support natively manipulating structured data. There is quite a gap between the shell supporting it and tools supporting it, though, and it's a bit of a chicken-and-egg problem.
This shows how much our old-school Unix tools need an update.
What if all the CLI tools had an option for JSON output and the shell natively supported a query language like `jq`. Then you could pipe commands together:
This assumes the default output would still be the legacy text format. But if the default output changed to JSON then you could get rid of the ugly json-in/out syntax.