Hacker News new | ask | show | jobs
by nailer 3627 days ago
This is good, but the data structures - eg arrays of arrays - don't really match the underlying data. Imagine what 'ip addr' or 'ifconfig' would look like - they output paragraphs rather than lines, so scraping lines wouldn't produce good output.

It'd be better - and FAR more work - to make an object pipeline based powershell equivalent for Nix, based on JSON. You could write cmdlets in any language that outputs JSON and do better at this project's goal of avoiding scraping.

    ps node | select pid
instead of:

    ps().find(function(line){ return line[3] === 'node' })[0]
Since the fields have keys, you avoid magic numbers and the code's easier to read.

(you could of course alias those to make 'pidof node' like Linux distros do)

The end result would be much better than Powershell, since it would use JSON and not be tied to .net languages.

1 comments

That sounds so good and better. Thank you, I will work on it.
Consider:

wrapPs( "ps -ef" ) => [ {pid: 1234, name: "foo.sh" }, ... ]

wrapLs( "ls -al" ) => [ ... ]

(not the syntax but the idea). You want to allow interested individuals to write the wrappers "forcefully" against uncooperative maintainers (separate people, separate ideas, separate motivations, separate release cycle, etc).

Eventually, some enlightened shell-command owners might add "ls -al --json" or "ps -ef --json", "git stat --json" which removes the need for a wrapper script, but the wrapper script allows innovation peripheral to the core without affecting the core until finally due to overwhelming support the core is extended with something "good" and agreed upon via consensus usage.

For the short term, perhaps if "ps" and "ps.wrap" exist in your path, your awkward shell can inject the "* .wrap" automatically around the given command in a way that doesn't require a lot of typing, either automatically, or via shortened syntax.

(ps -ef).map(...)

!(ps -ef).map(...)

{{ ps -ef }}.map(...)

I don't know but eventually you'd want to get to a point where you're bridging between the interactive use case (ps -ef printing a nice text table) and the pipeline use case (ps -ef --json letting you easily access different fields), maybe {{ ps -ef }} either calls * .wrap if it exists or if it doesn't exist calls it with --json (this assumes the command supports --json directly)

Regardless, this idea has some legs and I look forward to seeing how much traction it gets.