

Plumbum: Pythonic Shell Combinators - mnazim
https://github.com/tomerfiliba/plumbum

======
friggeri
Someone needs to explain to me in what parallel universe

    
    
        (sudo[ifconfig["-a"]] | grep["-i", "loop"]) & FG
    

is more readable than

    
    
        sudo ifconfig -a | grep -i loop &

~~~
tav
It's not. The reasons that one might use `plumbum` are similar to the reasons
that one might use `fabric` instead of just running local/remote shell
scripts, i.e.

\- Ability to leverage the richness of Python to pre/post-process the
inputs/outputs from other shell commands.

\- Easier to parameterise and maintain.

\- Familiarity with Python over the likes of bash, zsh, etc.

~~~
gbog
Em, the fabric version would be much more readable I'm not mistaken:

local("ls - l | grep foo")

~~~
jshharlow
From looking at the code it seems like plumbum is more object oriented,
instead of having stuff like
[https://github.com/fabric/fabric/blob/master/fabric/state.py...](https://github.com/fabric/fabric/blob/master/fabric/state.py#L267)
in fabric, so thats a good move forward.

~~~
cheatercheater
Yes, because OOP is salvation. Right?

~~~
harlowja
Right, lol.

------
tveita
I'm sure it's convenient, but I wouldn't call this kind of operator
overloading "pythonic".

Not to say being pythonic is always better, but some of these tricks don't
even seem that practical. Why "& FG" instead of .fg()? Using division for
joining paths is cute, but why not use '+', the conventional append operator?

~~~
tomerfiliba
&FG and &BG are just shell-ish shortcuts. you can always use .popen() or
.run()

------
jal278
This reminds me of when I first saw drop-box: Immediate recognition of the
pain it will save me. I often hack up kludges that approximate this --
os.system calls that pipe to a file, then I read and parse the file. Good
work.

~~~
robrenaud
The commands module is now deprecated by the overly complicated subprocess
module, but

    
    
         content = commands.getoutput(x)
     

is much better than

    
    
         os.system(x + ' > foo') 
         content = open('foo', 'r').read()

~~~
icebraining
The subprocess mode is really not that complicated. Your example can be
written as:

    
    
        content = subprocess.check_output(x, shell=True)

------
colinmarc
Some really clever tricks here. I particularly like the __getitem__ one. I'm
simultaneously excited and filled with horror. =)

------
gbog
I think this attempt and other simile are fun but I doubt I would use them for
serious things. Maybe it should be done the other way: like markdown is an
extension of html, we could have an extension of shell with python syntax.

------
cing
While we're on the topic, here's another shell scripting package for Python:
<https://github.com/amoffat/pbs>

~~~
tomerfiliba
see <http://readthedocs.org/docs/plumbum/en/latest/#credits>

------
jhales
I'm not quite sure I understand the value added over "!ls" etc on iPython. Is
this module primarily for use on the vanilla interpreter?

------
mariocesar
The coolest thing I see this year!

------
ehosca
thats Lead ....

------
cheatercheater
Haskell has done it long ago and much better:

<http://news.ycombinator.com/item?id=3966630>

