-
Notifications
You must be signed in to change notification settings - Fork 10
Support pipes #16
Comments
Is there a ruby way to do this?
|
Maybe we could write a |
A commandline call would then look like this:
vs.
What do you think now? |
I think it's more suitable to lisp :) Plus it's more ugly than in bash. |
Sorry if I was unclear, I meant a variable length argument list. It would look like this: pipe :ls, :grep, :less It would still need a way to add arguments though. |
pipe ls: "-a" , grep: ["-E", /foo/], :less Would be much better. Okay, I'm stopping the trolling here now. This problem is rather hard to accomplish, yes. I would personally go like this:
So basically just what the bash does. We could prettify this with some neat keywords or something:
or whatever. |
http://stackoverflow.com/a/9834134/1685746 ah, it pushes that data to stdin. Oookay, I'll think how to implement that in ruby.
I'm not sure which one is better. |
Now I'm really thinking about how clojure deals with all that braces. They have threading macro that work
|
@s-mage I'm not sure what you are referring to by "braces". I assume you are referring to two different approaches to pipelining here:
In my opinion, the first option would be superior, as a shell needs to allow piping more than just In terms of what |
Hi, I'm back. FYI, ruby supports pipelines via Open3 lib: http://ruby-doc.org/stdlib-2.0.0/libdoc/open3/rdoc/Open3.html So one possible solution is just use Open3.pipeline, but it's not very convenient. Another way is build my own pipeline based on popen3 (or maybe popen2). In the end it should look like this
|
Example with Open3 |
So I'd monkeypatch String class method_missing method, but it causes errors (I've just tried). Maybe I should create my own class and wrap every command output? Or is there more elegant solution? |
I think that could work. Something like this: class Pipe
...
def method_missing(cmd, args*)
...
end
end
pipe = Pipe.new someDir
print pipe.ls.grep('cow').hexdump Or a more bash-like syntax: class Pipe
...
def |(pipe)
...
end
end
ls = Pipe.new 'ls'
grep = Pipe.new 'grep'
hexdump = Pipe.new 'hexdump'
ls | grep('cow') | hexdump |
As a breaking change, The problem is that you're considering file names must be sane, and you can "simply newline split them", you're gonna have a bad time. Using glob syntax and the Array it returns will (most of the time) free you from having to deal with those dangerous minutae. If you don't, use at least
*not available on all flavours of ls such as busybox ls. |
@lostinblue Why not file.write 'string' ? https://github.com/s-mage/rush/wiki/Handbook%3A-File-Contents |
Would be nice if piping would be supported:
or provide some better interfaces for this:
The text was updated successfully, but these errors were encountered: