mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-06-17 00:07:37 +02:00
add alternate magic syntax
This commit is contained in:
158
README.md
158
README.md
@ -17,6 +17,20 @@ $ ls -l /usr/bin | jc --ls | jq '.[] | select(.size > 50000000)'
|
|||||||
"date": "Aug 14 19:41"
|
"date": "Aug 14 19:41"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
or using the alternative syntax:
|
||||||
|
```
|
||||||
|
$ jc ls -l /usr/bin | jq '.[] | select(.size > 50000000)'
|
||||||
|
{
|
||||||
|
"filename": "docker",
|
||||||
|
"flags": "-rwxr-xr-x",
|
||||||
|
"links": 1,
|
||||||
|
"owner": "root",
|
||||||
|
"group": "root",
|
||||||
|
"size": 68677120,
|
||||||
|
"date": "Aug 14 19:41"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
For more information on the motivations for this project, please see my blog post at https://blog.kellybrazil.com/2019/11/26/bringing-the-unix-philosophy-to-the-21st-century/.
|
For more information on the motivations for this project, please see my blog post at https://blog.kellybrazil.com/2019/11/26/bringing-the-unix-philosophy-to-the-21st-century/.
|
||||||
|
|
||||||
The `jc` parsers can also be used as python modules. In this case the output will be a python dictionary instead of JSON:
|
The `jc` parsers can also be used as python modules. In this case the output will be a python dictionary instead of JSON:
|
||||||
@ -58,47 +72,55 @@ $ pip3 install --upgrade jc
|
|||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
```
|
```
|
||||||
jc PARSER [OPTIONS]
|
COMMAND | jc PARSER [OPTIONS]
|
||||||
|
```
|
||||||
|
or
|
||||||
|
```
|
||||||
|
COMMAND | jc [OPTIONS] PARSER
|
||||||
|
```
|
||||||
|
or
|
||||||
|
```
|
||||||
|
jc [OPTIONS] COMMAND
|
||||||
```
|
```
|
||||||
|
|
||||||
`jc` accepts piped input from `STDIN` and outputs a JSON representation of the previous command's output to `STDOUT`. The JSON output can be compact or pretty formatted.
|
`jc` accepts piped input from `STDIN` and outputs a JSON representation of the previous command's output to `STDOUT`. The JSON output can be compact or pretty formatted.
|
||||||
|
|
||||||
### Parsers
|
### Parsers
|
||||||
- `--arp` enables the `arp` parser
|
- `--arp` enables the `arp` command parser
|
||||||
- `--crontab` enables the `crontab` file parser
|
- `--crontab` enables the `crontab` command and file parser
|
||||||
- `--crontab-u` enables the `crontab` file parser with user support
|
- `--crontab-u` enables the `crontab` file parser with user support
|
||||||
- `--df` enables the `df` parser
|
- `--df` enables the `df` command parser
|
||||||
- `--dig` enables the `dig` parser
|
- `--dig` enables the `dig` command parser
|
||||||
- `--du` enables the `du` parser
|
- `--du` enables the `du` command parser
|
||||||
- `--env` enables the `env` parser
|
- `--env` enables the `env` command parser
|
||||||
- `--free` enables the `free` parser
|
- `--free` enables the `free` command parser
|
||||||
- `--fstab` enables the `/etc/fstab` file parser
|
- `--fstab` enables the `/etc/fstab` file parser
|
||||||
- `--history` enables the `history` parser
|
- `--history` enables the `history` command parser
|
||||||
- `--hosts` enables the `/etc/hosts` file parser
|
- `--hosts` enables the `/etc/hosts` file parser
|
||||||
- `--id` enables the `id` parser
|
- `--id` enables the `id` command parser
|
||||||
- `--ifconfig` enables the `ifconfig` parser
|
- `--ifconfig` enables the `ifconfig` command parser
|
||||||
- `--ini` enables the `INI` file parser
|
- `--ini` enables the `INI` file parser
|
||||||
- `--iptables` enables the `iptables` parser
|
- `--iptables` enables the `iptables` command parser
|
||||||
- `--jobs` enables the `jobs` parser
|
- `--jobs` enables the `jobs` command parser
|
||||||
- `--ls` enables the `ls` parser
|
- `--ls` enables the `ls` command parser
|
||||||
- `--lsblk` enables the `lsblk` parser
|
- `--lsblk` enables the `lsblk` command parser
|
||||||
- `--lsmod` enables the `lsmod` parser
|
- `--lsmod` enables the `lsmod` command parser
|
||||||
- `--lsof` enables the `lsof` parser
|
- `--lsof` enables the `lsof` command parser
|
||||||
- `--mount` enables the `mount` parser
|
- `--mount` enables the `mount` command parser
|
||||||
- `--netstat` enables the `netstat` parser
|
- `--netstat` enables the `netstat` command parser
|
||||||
- `--pip-list` enables the `pip list` parser
|
- `--pip-list` enables the `pip list` command parser
|
||||||
- `--pip-show` enables the `pip show` parser
|
- `--pip-show` enables the `pip show` command parser
|
||||||
- `--ps` enables the `ps` parser
|
- `--ps` enables the `ps` command parser
|
||||||
- `--route` enables the `route` parser
|
- `--route` enables the `route` command parser
|
||||||
- `--ss` enables the `ss` parser
|
- `--ss` enables the `ss` command parser
|
||||||
- `--stat` enables the `stat` parser
|
- `--stat` enables the `stat` command parser
|
||||||
- `--systemctl` enables the `systemctl` parser
|
- `--systemctl` enables the `systemctl` command parser
|
||||||
- `--systemctl-lj` enables the `systemctl list-jobs` parser
|
- `--systemctl-lj` enables the `systemctl list-jobs` command parser
|
||||||
- `--systemctl-ls` enables the `systemctl list-sockets` parser
|
- `--systemctl-ls` enables the `systemctl list-sockets` command parser
|
||||||
- `--systemctl-luf` enables the `systemctl list-unit-files` parser
|
- `--systemctl-luf` enables the `systemctl list-unit-files` command parser
|
||||||
- `--uname` enables the `uname -a` parser
|
- `--uname` enables the `uname -a` command parser
|
||||||
- `--uptime` enables the `uptime` parser
|
- `--uptime` enables the `uptime` command parser
|
||||||
- `--w` enables the `w` parser
|
- `--w` enables the `w` command parser
|
||||||
- `--xml` enables the `XML` file parser
|
- `--xml` enables the `XML` file parser
|
||||||
- `--yaml` enables the `YAML` file parser
|
- `--yaml` enables the `YAML` file parser
|
||||||
|
|
||||||
@ -112,7 +134,7 @@ jc PARSER [OPTIONS]
|
|||||||
## Examples
|
## Examples
|
||||||
### arp
|
### arp
|
||||||
```
|
```
|
||||||
$ arp | jc --arp -p
|
$ arp | jc --arp -p # or: jc -p arp
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"address": "gateway",
|
"address": "gateway",
|
||||||
@ -138,7 +160,7 @@ $ arp | jc --arp -p
|
|||||||
]
|
]
|
||||||
```
|
```
|
||||||
```
|
```
|
||||||
$ arp -a | jc --arp -p
|
$ arp -a | jc --arp -p # or: jc -p arp -a
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"name": null,
|
"name": null,
|
||||||
@ -165,7 +187,7 @@ $ arp -a | jc --arp -p
|
|||||||
```
|
```
|
||||||
### crontab
|
### crontab
|
||||||
```
|
```
|
||||||
$ cat /etc/crontab | jc --crontab -p
|
$ cat /etc/crontab | jc --crontab -p # or: jc -p crontab -l
|
||||||
{
|
{
|
||||||
"variables": [
|
"variables": [
|
||||||
{
|
{
|
||||||
@ -312,7 +334,7 @@ $ cat /etc/crontab | jc --crontab-u -p
|
|||||||
```
|
```
|
||||||
### df
|
### df
|
||||||
```
|
```
|
||||||
$ df | jc --df -p
|
$ df | jc --df -p # or: jc -p df
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"filesystem": "devtmpfs",
|
"filesystem": "devtmpfs",
|
||||||
@ -335,7 +357,7 @@ $ df | jc --df -p
|
|||||||
```
|
```
|
||||||
### dig
|
### dig
|
||||||
```
|
```
|
||||||
$ dig cnn.com www.cnn.com @205.251.194.64 | jc --dig -p
|
$ dig cnn.com www.cnn.com @205.251.194.64 | jc --dig -p # or: jc -p dig cnn.com www.cnn.com @205.251.194.64
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"id": 5509,
|
"id": 5509,
|
||||||
@ -455,7 +477,7 @@ $ dig cnn.com www.cnn.com @205.251.194.64 | jc --dig -p
|
|||||||
]
|
]
|
||||||
```
|
```
|
||||||
```
|
```
|
||||||
$ dig -x 1.1.1.1 | jc --dig -p
|
$ dig -x 1.1.1.1 | jc --dig -p # or: jc -p dig -x 1.1.1.1
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"id": 50324,
|
"id": 50324,
|
||||||
@ -493,7 +515,7 @@ $ dig -x 1.1.1.1 | jc --dig -p
|
|||||||
```
|
```
|
||||||
### du
|
### du
|
||||||
```
|
```
|
||||||
$ du /usr | jc --du -p
|
$ du /usr | jc --du -p # or: jc -p du /usr
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"size": 104608,
|
"size": 104608,
|
||||||
@ -524,7 +546,7 @@ $ du /usr | jc --du -p
|
|||||||
```
|
```
|
||||||
### env
|
### env
|
||||||
```
|
```
|
||||||
$ env | jc --env -p
|
$ env | jc --env -p # or: jc -p env
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"name": "XDG_SESSION_ID",
|
"name": "XDG_SESSION_ID",
|
||||||
@ -551,7 +573,7 @@ $ env | jc --env -p
|
|||||||
```
|
```
|
||||||
### free
|
### free
|
||||||
```
|
```
|
||||||
$ free | jc --free -p
|
$ free | jc --free -p # or: jc -p free
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"type": "Mem",
|
"type": "Mem",
|
||||||
@ -602,7 +624,7 @@ $ cat /etc/fstab | jc --fstab -p
|
|||||||
```
|
```
|
||||||
### history
|
### history
|
||||||
```
|
```
|
||||||
$ history | jc --history -p
|
$ history | jc --history -p # or: jc -p history
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"line": 118,
|
"line": 118,
|
||||||
@ -674,7 +696,7 @@ $ cat /etc/hosts | jc --hosts -p
|
|||||||
```
|
```
|
||||||
### id
|
### id
|
||||||
```
|
```
|
||||||
$ id | jc --id -p
|
$ id | jc --id -p # or: jc -p id
|
||||||
{
|
{
|
||||||
"uid": {
|
"uid": {
|
||||||
"id": 1000,
|
"id": 1000,
|
||||||
@ -704,7 +726,7 @@ $ id | jc --id -p
|
|||||||
```
|
```
|
||||||
### ifconfig
|
### ifconfig
|
||||||
```
|
```
|
||||||
$ ifconfig | jc --ifconfig -p
|
$ ifconfig | jc --ifconfig -p # or: jc -p ifconfig
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"name": "ens33",
|
"name": "ens33",
|
||||||
@ -809,7 +831,7 @@ $ cat example.ini | jc --ini -p
|
|||||||
```
|
```
|
||||||
### iptables
|
### iptables
|
||||||
```
|
```
|
||||||
$ sudo iptables --line-numbers -v -L -t nat | jc --iptables -p
|
$ sudo iptables --line-numbers -v -L -t nat | jc --iptables -p # or: sudo jc -p iptables --line-numbers -v -L -t nat
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"chain": "PREROUTING",
|
"chain": "PREROUTING",
|
||||||
@ -870,7 +892,7 @@ $ sudo iptables --line-numbers -v -L -t nat | jc --iptables -p
|
|||||||
```
|
```
|
||||||
### jobs
|
### jobs
|
||||||
```
|
```
|
||||||
$ jobs -l | jc --jobs -p
|
$ jobs -l | jc --jobs -p # or: jc -p jobs
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"job_number": 1,
|
"job_number": 1,
|
||||||
@ -902,7 +924,7 @@ $ jobs -l | jc --jobs -p
|
|||||||
```
|
```
|
||||||
### ls
|
### ls
|
||||||
```
|
```
|
||||||
$ ls -l /usr/bin | jc --ls -p
|
$ ls -l /usr/bin | jc --ls -p # or: jc -p ls -l /usr/bin
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"filename": "apropos",
|
"filename": "apropos",
|
||||||
@ -937,7 +959,7 @@ $ ls -l /usr/bin | jc --ls -p
|
|||||||
```
|
```
|
||||||
### lsblk
|
### lsblk
|
||||||
```
|
```
|
||||||
$ lsblk | jc --lsblk -p
|
$ lsblk | jc --lsblk -p # or: jc -p lsblk
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"name": "sda",
|
"name": "sda",
|
||||||
@ -962,7 +984,7 @@ $ lsblk | jc --lsblk -p
|
|||||||
```
|
```
|
||||||
### lsmod
|
### lsmod
|
||||||
```
|
```
|
||||||
$ lsmod | jc --lsmod -p
|
$ lsmod | jc --lsmod -p # or: jc -p lsmod
|
||||||
[
|
[
|
||||||
...
|
...
|
||||||
{
|
{
|
||||||
@ -1009,7 +1031,7 @@ $ lsmod | jc --lsmod -p
|
|||||||
```
|
```
|
||||||
### lsof
|
### lsof
|
||||||
```
|
```
|
||||||
$ sudo lsof | jc --lsof -p
|
$ sudo lsof | jc --lsof -p # or: jc -p lsof
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"command": "systemd",
|
"command": "systemd",
|
||||||
@ -1052,7 +1074,7 @@ $ sudo lsof | jc --lsof -p
|
|||||||
```
|
```
|
||||||
### mount
|
### mount
|
||||||
```
|
```
|
||||||
$ mount | jc --mount -p
|
$ mount | jc --mount -p # or: jc -p mount
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"filesystem": "sysfs",
|
"filesystem": "sysfs",
|
||||||
@ -1096,7 +1118,7 @@ $ mount | jc --mount -p
|
|||||||
```
|
```
|
||||||
### netstat
|
### netstat
|
||||||
```
|
```
|
||||||
$ sudo netstat -apee | jc --netstat -p
|
$ sudo netstat -apee | jc --netstat -p # or: sudo jc -p netstat -apee
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"proto": "tcp",
|
"proto": "tcp",
|
||||||
@ -1248,7 +1270,7 @@ $ sudo netstat -apee | jc --netstat -p
|
|||||||
```
|
```
|
||||||
### pip list
|
### pip list
|
||||||
```
|
```
|
||||||
$ pip list | jc --pip-list -p
|
$ pip list | jc --pip-list -p # or: jc -p pip list # or: jc -p pip3 list
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"package": "ansible",
|
"package": "ansible",
|
||||||
@ -1268,7 +1290,7 @@ $ pip list | jc --pip-list -p
|
|||||||
```
|
```
|
||||||
### pip show
|
### pip show
|
||||||
```
|
```
|
||||||
$ pip show wrapt wheel | jc --pip-show -p
|
$ pip show wrapt wheel | jc --pip-show -p # or: jc -p pip show wrapt wheel # or: jc -p pip3 show wrapt wheel
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"name": "wrapt",
|
"name": "wrapt",
|
||||||
@ -1298,7 +1320,7 @@ $ pip show wrapt wheel | jc --pip-show -p
|
|||||||
```
|
```
|
||||||
### ps
|
### ps
|
||||||
```
|
```
|
||||||
$ ps -ef | jc --ps -p
|
$ ps -ef | jc --ps -p # or: jc -p ps -ef
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"uid": "root",
|
"uid": "root",
|
||||||
@ -1334,7 +1356,7 @@ $ ps -ef | jc --ps -p
|
|||||||
]
|
]
|
||||||
```
|
```
|
||||||
```
|
```
|
||||||
$ ps axu | jc --ps -p
|
$ ps axu | jc --ps -p # or: jc -p ps axu
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"user": "root",
|
"user": "root",
|
||||||
@ -1380,7 +1402,7 @@ $ ps axu | jc --ps -p
|
|||||||
```
|
```
|
||||||
### route
|
### route
|
||||||
```
|
```
|
||||||
$ route -ee | jc --route -p
|
$ route -ee | jc --route -p # or: jc -p route -ee
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"destination": "default",
|
"destination": "default",
|
||||||
@ -1425,7 +1447,7 @@ $ route -ee | jc --route -p
|
|||||||
```
|
```
|
||||||
### ss
|
### ss
|
||||||
```
|
```
|
||||||
$ sudo ss -a | jc --ss -p
|
$ sudo ss -a | jc --ss -p # or: sudo jc -p ss -a
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"netid": "nl",
|
"netid": "nl",
|
||||||
@ -1544,7 +1566,7 @@ $ sudo ss -a | jc --ss -p
|
|||||||
```
|
```
|
||||||
### stat
|
### stat
|
||||||
```
|
```
|
||||||
$ stat /bin/* | jc --stat -p
|
$ stat /bin/* | jc --stat -p # or: jc -p stat /bin/*
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"file": "/bin/bash",
|
"file": "/bin/bash",
|
||||||
@ -1591,7 +1613,7 @@ $ stat /bin/* | jc --stat -p
|
|||||||
```
|
```
|
||||||
### systemctl
|
### systemctl
|
||||||
```
|
```
|
||||||
$ systemctl -a | jc --systemctl -p
|
$ systemctl -a | jc --systemctl -p # or: jc -p systemctl -a
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"unit": "proc-sys-fs-binfmt_misc.automount",
|
"unit": "proc-sys-fs-binfmt_misc.automount",
|
||||||
@ -1619,7 +1641,7 @@ $ systemctl -a | jc --systemctl -p
|
|||||||
```
|
```
|
||||||
### systemctl list-jobs
|
### systemctl list-jobs
|
||||||
```
|
```
|
||||||
$ systemctl list-jobs| jc --systemctl-lj -p
|
$ systemctl list-jobs | jc --systemctl-lj -p # or: jc -p systemctl list-jobs
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"job": 3543,
|
"job": 3543,
|
||||||
@ -1643,7 +1665,7 @@ $ systemctl list-jobs| jc --systemctl-lj -p
|
|||||||
```
|
```
|
||||||
### systemctl list-sockets
|
### systemctl list-sockets
|
||||||
```
|
```
|
||||||
$ systemctl list-sockets | jc --systemctl-ls -p
|
$ systemctl list-sockets | jc --systemctl-ls -p # or: jc -p systemctl list-sockets
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"listen": "/dev/log",
|
"listen": "/dev/log",
|
||||||
@ -1665,7 +1687,7 @@ $ systemctl list-sockets | jc --systemctl-ls -p
|
|||||||
```
|
```
|
||||||
### systemctl list-unit-files
|
### systemctl list-unit-files
|
||||||
```
|
```
|
||||||
$ systemctl list-unit-files | jc --systemctl-luf -p
|
$ systemctl list-unit-files | jc --systemctl-luf -p # or: jc -p systemctl list-unit-files
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"unit_file": "proc-sys-fs-binfmt_misc.automount",
|
"unit_file": "proc-sys-fs-binfmt_misc.automount",
|
||||||
@ -1684,7 +1706,7 @@ $ systemctl list-unit-files | jc --systemctl-luf -p
|
|||||||
```
|
```
|
||||||
### uname -a
|
### uname -a
|
||||||
```
|
```
|
||||||
$ uname -a | jc --uname -p
|
$ uname -a | jc --uname -p # or: jc -p uname -a
|
||||||
{
|
{
|
||||||
"kernel_name": "Linux",
|
"kernel_name": "Linux",
|
||||||
"node_name": "user-ubuntu",
|
"node_name": "user-ubuntu",
|
||||||
@ -1698,7 +1720,7 @@ $ uname -a | jc --uname -p
|
|||||||
```
|
```
|
||||||
### uptime
|
### uptime
|
||||||
```
|
```
|
||||||
$ uptime | jc --uptime -p
|
$ uptime | jc --uptime -p # or: jc -p uptime
|
||||||
{
|
{
|
||||||
"time": "11:30:44",
|
"time": "11:30:44",
|
||||||
"uptime": "1 day, 21:17",
|
"uptime": "1 day, 21:17",
|
||||||
@ -1710,7 +1732,7 @@ $ uptime | jc --uptime -p
|
|||||||
```
|
```
|
||||||
### w
|
### w
|
||||||
```
|
```
|
||||||
$ w | jc --w -p
|
$ w | jc --w -p # or: jc -p w
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"user": "root",
|
"user": "root",
|
||||||
@ -1792,7 +1814,7 @@ $ cat cd_catalog.xml | jc --xml -p
|
|||||||
```
|
```
|
||||||
### YAML files
|
### YAML files
|
||||||
```
|
```
|
||||||
$ cat istio-mtls-permissive.yaml
|
$ cat istio.yaml
|
||||||
apiVersion: "authentication.istio.io/v1alpha1"
|
apiVersion: "authentication.istio.io/v1alpha1"
|
||||||
kind: "Policy"
|
kind: "Policy"
|
||||||
metadata:
|
metadata:
|
||||||
@ -1813,7 +1835,7 @@ spec:
|
|||||||
tls:
|
tls:
|
||||||
mode: ISTIO_MUTUAL
|
mode: ISTIO_MUTUAL
|
||||||
|
|
||||||
$ cat istio-mtls-permissive.yaml | jc --yaml -p
|
$ cat istio.yaml | jc --yaml -p
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"apiVersion": "authentication.istio.io/v1alpha1",
|
"apiVersion": "authentication.istio.io/v1alpha1",
|
||||||
|
Reference in New Issue
Block a user