Have you seen nushell? It lets me one-liner so many things that would have previously taken breaking out a "real" language to do
Contrived example:
ls | where type == 'file' | sort-by size | take 4 | each {|f| {n: $f.name, s: ($f.size | format filesize MB) }} | to json
outputs {
"n": "clippy.toml",
"s": "0.000001 MB"
},
{
"n": "README.md",
"s": "0.000009 MB"
},
{
"n": "rustfmt.toml",
"s": "0.000052 MB"
},
{
"n": "typos.toml",
"s": "0.00009 MB"
}I've tried nushell and other shell replacements and it just feels like I'm learning a new programming language for no good reason
In PowerShell:
gci -file | sort-object size | select name, size -first 4 | % { $_.size /= 1MB; $_ } | ConvertTo-JsonFor me the best benefit of nushell is not the easier syntax, but the static type checks. It catches most typos before running the script, which is a godsend when the script is slow and/or has destructive operations.
Was just about to suggest nushell. I love programming in nushell, the out of the box features are excellent.
this is pretty cool!
With this:
This becomes valid Ruby: (drops your size formatting, so not strictly equivalent)Which isn't meant to "compete" - nushell looks nice -, but to show that the lower-threshold option for those of us who don't want to switch shells is to throw together a few helpers in a language... (you can get much closer to your example with another helper or two and a few more "evil" abuses of Ruby's darker corners, but I'm not sure it'd be worth it; I might a wrapper for the above in my bin/ though)