toolshed
toolshed copied to clipboard
Make it possible to pipe utilities
At a shell prompt, it's really convenient to be able to pipe the output from one command into another. The current toolshed commands don't let you do this. Here's an example that would be nice to support:
iex> cat("/etc/services") |> grep(~r/ntp/)
... all lines with `ntp` in them...
The refactor
branch has a start at implementing this.
Does this boil down to letting functions return an Elixir representation instead of printing the result and returning :"do not show this result in output"
?
-
cat/1
can return a string - Some functions like
dmesg/0
might be OK as is...
Maybe we want to think of specific scenarios where pipe-ability is handy like cat + grep. Is there anything else?
I suppose that I regularly pipe output when using bash
, so this comes up all the time for me. I want to grep pretty much everything that returns a string in Elixir. This includes non-Toolshed things like inspect
and traces too. Piping is also useful for redirecting text output to files or transfer over the network so that the text can be looked using an editor.
Fwiw, I prototyped this feature a couple years ago in the refactor
branch. That branch needs some work to bring it up to date, but I'd be willing to put that in if there's interest.
Ah wrapping the result in a standardized struct, nice! It works like a charm.
I think pipe-ability will be a huge appeal to Elixir programmers. Also if you yourself want to do the piping all the time, that is a good reason to implement the feature since you are one of the Nerves heavy users.
I could inherit your work if you rebase it on the latest main. There seem to be some major merge conflicts.
I rebased the refactor
branch into the pipes
branch. It's definitely part complete. This looks like a decent amount of work since there are a lot of commands and some of them look like they need some thought to pipe nicely. I'm wondering if it might be easier to tackle a couple easier issues before this one. Perhaps we should strategize on this after you get a chance to look over the branch more.