Skip to content

Instantly share code, notes, and snippets.

@irskep
Forked from timtadh/stevepipes.rst
Created December 1, 2011 20:29
Show Gist options
  • Save irskep/1419605 to your computer and use it in GitHub Desktop.
Save irskep/1419605 to your computer and use it in GitHub Desktop.
Pipes3k

Commands defined and referenced by [ID]: "command in quotes"

After definition, commands may be referenced by ID

Connections defined by reference => reference [=> reference ...]

Expressions are separated by ;

  • file1.txt: one
  • file2.txt: two
> "cat file1.txt" => "echo";
one

> A: "cat file1.txt"; B: "echo"; A -> B;
one

> A: "cat file 1.txt" => B: "echo" => C: "echo"; A => C;
one
one

stdout is piped with =>, =out>, or =0>

stderr is piped with =err>, or =1>

Other pipes are probably piped with =#>

Arrow supports most of Python slice syntax, so =0:2> is stdout and stderr, =0:-1> is all but the last output pipe, and =:> is all output pipes.

  • double_out: print out to stdout, print err to stderr
  • merge_pipes: non-deterministically merge all input pipes into one based on time
> "double_out" => "echo";
out

> "double_out" =out> "echo";
out

> "double_out" =err> "echo";
err

> "double_out" =:> "merge_pipes";
out
err

Now imagine that identifiers are persistent as long as the program is still running, so you can have a less-like program running in some window and can dynamically send arbitrary output to it from another terminal.

expressions are separated by commas, ,, commands by semicolons, ;.

Bash Inspiration

expressions

Bash example

find . -name '.py' | grep -v env | grep -v Test | xargs wc

commands

Bash example (note the && is what makes this have several commands)

cat ./example/0.ast | ./dotty | dot -Tpng > out.png && gwenview out.png

New Syntax

expressions (with named pipes)

diff the word counts of a project including the env and excluding the env.

2diff: diff 2 input streams

find . -name '.py' 1>|find| | grep -v env | grep -v Test | xargs wc 1>|noenv|, |find| xargs wc 1> |env| \
      2diff 0<|env| 3<|noenv|

Steve's alternate version:

find . -name '.py' |0>find_pipe| grep -v env | grep -v Test | xargs wc |0>noenv|, \
      |find_pipe| xargs wc |0>env|, \
      |[env, noenv]>| 2diff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment