v0.6
New in v0.6
Simpler more concise syntax
v0.6 simplifies pol syntax even further.
v0.6
netstat -an | grep ESTABLISHED | pol "|url(_4).hostname" "counter(_)" ":x, c: Cols(17,40).f(x,'*' * c)"
vs.
v0.1
netstat -an | pol "l=[l[4].split(':')[0] for l in _ if len(l)>5 and l[5]=='ESTABLISHED']; s=sorted([{'h':e,'c':l.count(e)} for e in set(l)],key=lambda k: k['c'], reverse=True); map(print,['{}\t{}'.format(i['h'],'*' * i['c']) for i in s])"
Example output:
216.58.193.78 *****
74.125.199.189 ****
198.252.206.25 ***
74.125.199.188 **
192.30.253.125 **
127.0.0.1 **
216.58.193.67 *
df -B1 | pol "|Cols(20,10,10,10,5,None,10).f(_0,_1.h(),_2.h(),_3.h(),_4, barchart(_2.i()/_1.f(),p=True) if _1.isdigit() else ' '*10,_5)"
Example output:
Filesystem 1B-blocks Used Available Use% Mounted
/dev/mapper/docker-8 9.99 G 8.06 G 1.93 G 81% ▓▓▓▓▓▓▓▓░░ /
tmpfs 31.37 G 0.00 B 31.37 G 0% ░░░░░░░░░░ /dev
tmpfs 31.37 G 0.00 B 31.37 G 0% ░░░░░░░░░░ /sys/fs/cg
/dev/sda3 211.08 G 26.49 G 173.84 G 14% ▓░░░░░░░░░ /etc/hosts
shm 64.00 M 0.00 B 64.00 M 0% ░░░░░░░░░░ /dev/shm
The simplification has been achieved with the help of the enhancements described below.
Chaining expressions
You can chain expressions as if you were chaining commands on bash using pipes.
netstat -an | grep ESTABLISHED | pol "|url(_4).hostname" "counter(_)" ":x, c: Cols(17,40,None).f(x, get([' '.join(l[1:]) for l in sh(['whois', x],s=T) if 'OrgName' in l[0]], 0), '*' * c)"
Expression types
Awk-like expressions
|epxression
%FS%expression
Works on the last result item by item (or line by line if the last result was stdin
)
The split() is called |epxression
and split(FS) is called with %FS%expression
.
The list generated by the split is available in __
.
Individual fields are available as _0
, _1
, _2
etc.
ps aux | pol "|Cols(10,None).f(_0,_10)"
USER COMMAND
default bash
default ps
default /tmp/poline/poline_venv/bin/python
lambda-like expressions
:*args:expression
Works on the last result item by item (or line by line if the last result was stdin
)
Receives the n-tuple *args.
Example
ps aux | pol "skip(_)" "|(_0,_10)" ":user,cmd:Cols(50,None).f(next(sh('id',user)),cmd)"
uid=1001(default) gid=0(root) groups=0(root) bash
uid=1001(default) gid=0(root) groups=0(root) ps
uid=1001(default) gid=0(root) groups=0(root) /tmp/poline/poline_venv/bin/python
New utility functions and classes
skip(iter, n=1)
Skip the first n
items from the Iterator iter
.
pol "ls('-lah')" "skip(_,n=3)"
-rw-r--r-- 1 default root 0 Mar 31 14:33 __init__.py
-rw-r--r-- 1 default root 1.7K Apr 2 23:31 _com_collections.py
-rw-r--r-- 1 default root 4.2K Apr 2 23:33 core.py
-rw-r--r-- 1 default root 750 Apr 2 23:34 fields.py
-rw-r--r-- 1 default root 3.4K Apr 2 23:31 utilfuncs.py
class Cols
Cols is used to manage formatted output in the form of columns
__init__(*args, **kwargs)
The constructor generators columns by unpacking *args. For example:
Cols(10,10,20,None)
generates a format string as '{10.10}\t{10.10}\t{20.20}\t{}'
f(*args, **kwargs)
Unpacks *args
to pass to String.format()
. If format string has not been set, sets the format string as {}\t{}