bin: handle exotic json in cj and b
This commit is contained in:
parent
cee9843528
commit
936c4ab5e2
|
@ -99,7 +99,7 @@ for arg; do
|
|||
case "$(file --dereference "$arg")" in
|
||||
(*\ ?udio*)
|
||||
# TODO preconvert aac - |*\ ADTS\ *
|
||||
if ! $inspect && which audiowaveform 2>/dev/null >&2; then
|
||||
if ! $inspect && which audiowaveform >/dev/null; then
|
||||
img="$tmpfile.png"
|
||||
case $TERM in (*-kitty) kitty=true; audioheight=2;; (*) audioheight=5;; esac
|
||||
find "$img" -not -empty 2>/dev/null | grep --quiet . ||
|
||||
|
@ -177,7 +177,8 @@ if test "$bat" -o "$batplain"; then
|
|||
batcommand="$elevate bat $cut $flags --pager"
|
||||
batstyle="--style plain$rule"
|
||||
test "$batplain" && $batcommand "${batpager:-$pager}" $batstyle "${batplain[@]}"
|
||||
test "$bat" && if test "$cut" && ! $inspect
|
||||
test "$bat" &&
|
||||
if test "$cut" && ! $inspect
|
||||
then case $TERM in (*kitty)
|
||||
declare -a timgtxt
|
||||
for file in "${bat[@]}"
|
||||
|
@ -193,8 +194,23 @@ if test "$bat" -o "$batplain"; then
|
|||
fileinfo "$file"
|
||||
done;;
|
||||
esac
|
||||
else $inspect || $batcommand "${batpager:-$pager}" $batstyle,header$(test $# -gt 1 && echo ",numbers") "${bat[@]}"
|
||||
{ $inspect || test $# -lt $(expr $(tput lines) / 3); } && fileinfo "${bat[@]}"
|
||||
else
|
||||
if ! $inspect
|
||||
then json=false
|
||||
if which cj >/dev/null; then
|
||||
json=true
|
||||
for file in "${bat[@]}"; do
|
||||
case $file in (*.json);; (*) json=false;; esac
|
||||
done
|
||||
fi
|
||||
if $json
|
||||
then cj "${bat[@]}"
|
||||
else $batcommand "${batpager:-$pager}" $batstyle,header$(test $# -gt 1 && echo ",numbers") "${bat[@]}"
|
||||
fi
|
||||
fi
|
||||
if $inspect || test $# -lt $(expr $(tput lines) / 3);
|
||||
then fileinfo "${bat[@]}"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
|
|
|
@ -1,8 +1,18 @@
|
|||
#!/bin/sh
|
||||
#!/bin/bash
|
||||
# [c]at the given files as prettified [j]son
|
||||
# TODO quit on interrupt
|
||||
set -o pipefail
|
||||
|
||||
# jq if file is valid json, otherwise show parseable lines with bat
|
||||
unbuffer jq --unbuffered '' "$@" | less -F ||
|
||||
# add echo in case file is missing newline at the end
|
||||
{ cat "$@"; echo; } | while read -r line
|
||||
do test -n "$line" && python -c "import json; print(json.dumps($line, ensure_ascii=False))"
|
||||
{ for arg; do echo "FILE: $arg ─────────────────────────────────────────────────────────────────────────────────────────"; cat "$arg"; done; echo; } |
|
||||
while read -r line
|
||||
do
|
||||
line="${line%
}"
|
||||
if command expr length "$line" \> 2 \& "$line" : FILE = 0 >/dev/null
|
||||
then echo "${line%,}" | python3 -m json.tool --no-ensure-ascii --sort-keys
|
||||
else echo "$line"
|
||||
fi
|
||||
done | bat --language json --style numbers
|
||||
#bat --language json --style plain --pager json-format "$@"
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
#!/bin/sh -e
|
||||
# Format json as bat pager with python json.tool
|
||||
while read -r line
|
||||
do
|
||||
echo $line | bat -A
|
||||
line="$(echo ${line%
} | sed "s|.*\[0m\(.*\)|\1|")"
|
||||
echo $line | bat -A
|
||||
command expr length "$line" \> 2 &&
|
||||
echo "${line%,}" | python3 -m json.tool --no-ensure-ascii --sort-keys
|
||||
done
|
Loading…
Reference in New Issue