summary refs log tree commit diff
path: root/bin/jq-table
diff options
context:
space:
mode:
Diffstat (limited to 'bin/jq-table')
-rwxr-xr-xbin/jq-table8
1 files changed, 8 insertions, 0 deletions
diff --git a/bin/jq-table b/bin/jq-table
new file mode 100755
index 0000000..55d16fb
--- /dev/null
+++ b/bin/jq-table
@@ -0,0 +1,8 @@
+#!/bin/bash
+tsv=$(jq 'def hdr:to_entries|map(.key); def vals:to_entries|map(.value|tostring); (arrays|[(first|hdr)]+[.[]|vals]) // (objects|[hdr]+[vals])|.[]|@tsv' -r)
+col=$(head -n1 <<<"$tsv" | tr '\t' ',' | tr '[:lower:]' '[:upper:]')
+if [ "$1" = "--headers" ]; then
+	echo "$col"
+	exit 1
+fi
+exec column -s $'\t' --table --table-columns "$col" "$@" <(tail -n+2 <<<"$tsv")