1
1
mirror of https://github.com/wader/fq.git synced 2024-11-29 12:14:17 +03:00
fq/dev/format_summary.jq

35 lines
660 B
Plaintext
Raw Normal View History

2021-08-19 19:07:52 +03:00
#!/usr/bin/env fq -f
def recurse_depth(f; cond):
def _r($depth):
( ( .
| select(cond)
| {depth: $depth, value: .}
)
, ( [f]
| to_entries[] as $e
| $e.value
| _r($depth + if cond then 1 else 0 end)
)
);
_r(0);
[ ( recurse_depth(
.[]?;
2021-09-06 02:24:51 +03:00
format
2021-08-19 19:07:52 +03:00
)
| . + {
norm_path: (.value._path | map(if type == "number" then "index" end)),
}
)
]
| streaks_by(.norm_path)
2021-08-19 19:07:52 +03:00
| map(.[0] + {count: length})
| .[]
| [ if .depth > 0 then " "*.depth else empty end
2021-09-06 02:24:51 +03:00
, ((.value | format) + if .count > 1 then "*\(.count) " else " " end)
2021-08-19 19:07:52 +03:00
, (.value._path | path_to_expr)
]
| join("")
| println