Hacker News new | ask | show | jobs
by mdaniel 1521 days ago
I conceptually like pwsh, but even as your example shows, I don't have the RSI budget left to spend on typing that extremely verbose expression every day

jq and its unix-y friends allow me to trade off expressiveness against having to memorize arcane invocations

1 comments

I hear that, I use and like *nix too. PowerShell aliases help a lot. It comes with some predefined, like `gc` for `Get-Content`. The above example could be rewritten:

  gc cars.json | ConvertFrom-Json | ? color -eq 'red'
`ConvertFrom-Json` doesn't have a default alias, but you can define one in your PowerShell profile. I do that for commands I find myself using frequently. Say we pick convjson:

  gc cars.json | convjson | ? color -eq 'red'
That's more like what my typical pipelines look like.

The nice thing about aliases is you can always switch back to the verbose names when clarity is more important than brevity, like in long-term scripts.

Edit: Seems I've been using too many braces and dollar signs all these years. Thanks to majkinetor for the tip.

You don't need $_ for immediate properties which looks much cleaner:

    gc cars.json | convjson | ? color -eq 'red'
TIL! Thanks!