mpsh can perform various set theory operations on the output of programs, specified by special characters after pipes. Seperate lines of the text are parsed as set elements. For instance: the intersection of two commands includes only the lines that appear in the output of both commands:

mpsh$ ls dir1 |^ ls dir2

(Bear in mind that this follows set theory, not simple text filtering, so duplicates and original order are not maintained.)

You can treat the text output of any command as a set, or enter sets directly using curly braces (but with spaces instead of commas):

mpsh$ { red green } |U { blue orange }

mpsh$ ls |- { *.o }

The basic set theory operations are:

Union: |U
Intersection: |^
Difference: |\
Synonym for difference: |-
Symmetric difference: |o

You can also execute commands conditionally based on set theory tests.

If A is a subset of B, execute C:

mpsh$ command-a |< command-b ; command-c

If B is a subset of A, execute C:

mpsh$ command-a |> command-b ; command-c

If A equals B, execute C:

mpsh$ command-a |= command-b ; command-c

mpsh$ { red } |< { red green blue } ; echo red is a subset of rgb.
red is a subset of rgb.

Some more examples - take the intersection of *.c with the union of the outputs of command1 and command2, then send that to the sort command:

mpsh$ command1 |U command2 |^ { *.c } | sort

Open gimp with all the jpg's in the current directory, except *t.jpg:

mpsh$ gimp ( { *.jpg } |- { *t.jpg } )

The set theory operators are a bit superficial. Sets are deduplicated but subsets aren't, etc. Does not support infinite sets.