infix operator to pipe subprocess output to python function
Question:
Can xonsh pipe subprocess output to a python function?
int($(ls|wc -l)) > 20
as
ls | wc -l | int > 20
I can get close
from toolz import pipe
pipe($(ls |wc -l),int) > 20
this comes searching ways to port
# bash
[ $(ls |wc -l ) -gt 20 ] && echo busy dir
# xonsh
test @$(ls |wc -l) '-gt' 20 and echo busy dir
# xonsh with more python
len(`[^.].*`) > 20 and echo busy dir
But generally, I’m hoping for an infix operator a la magrittr‘s forward pipe %>%
or coconut’s |>
Answers:
Someone did the trick in the github issue comment using sspipe, https://github.com/xonsh/xonsh/issues/1336#issuecomment-502049121, but we can do it without it:
'Busy dir' if int($(ls | wc -l))>20 else ''
coconut supports xonsh
Coconut integrates with xonsh to allow the use of Coconut code directly from your command line. To use Coconut in xonsh, simply pip install coconut
and then run xontrib load coconut
from xonsh or add xontrib load coconut
to your xonshrc file.
https://coconut.readthedocs.io/en/latest/DOCS.html#xonsh-support
Can xonsh pipe subprocess output to a python function?
int($(ls|wc -l)) > 20
as
ls | wc -l | int > 20
I can get close
from toolz import pipe
pipe($(ls |wc -l),int) > 20
this comes searching ways to port
# bash
[ $(ls |wc -l ) -gt 20 ] && echo busy dir
# xonsh
test @$(ls |wc -l) '-gt' 20 and echo busy dir
# xonsh with more python
len(`[^.].*`) > 20 and echo busy dir
But generally, I’m hoping for an infix operator a la magrittr‘s forward pipe %>%
or coconut’s |>
Someone did the trick in the github issue comment using sspipe, https://github.com/xonsh/xonsh/issues/1336#issuecomment-502049121, but we can do it without it:
'Busy dir' if int($(ls | wc -l))>20 else ''
coconut supports xonsh
Coconut integrates with xonsh to allow the use of Coconut code directly from your command line. To use Coconut in xonsh, simply
pip install coconut
and then runxontrib load coconut
from xonsh or addxontrib load coconut
to your xonshrc file.
https://coconut.readthedocs.io/en/latest/DOCS.html#xonsh-support