From: Chris Koeritz Date: Wed, 8 Nov 2017 04:06:38 +0000 (-0500) Subject: nice new function json_view X-Git-Tag: 2.140.90~41 X-Git-Url: https://feistymeow.org/gitweb/?p=feisty_meow.git;a=commitdiff_plain;h=2c1c0c8a4f151d4b75c62db65dd9a5cadc753cc4 nice new function json_view takes a list of json files, pretty prints them, and sends them to standard out. shows the file names for each. --- diff --git a/scripts/core/functions.sh b/scripts/core/functions.sh index c750fff2..cbd9dbe0 100644 --- a/scripts/core/functions.sh +++ b/scripts/core/functions.sh @@ -742,6 +742,24 @@ return 0 echo "Created symlink from '$src' to '$target'." } + # pretty prints the json files provided as parameters. + function json_view() + { + if [ -z "$*" ]; then return; fi + local show_list=() + while true; do + local file="$1"; shift + if [ -z "$file" ]; then break; fi + if [ ! -f "$file" ]; then "echo File '$file' does not exist."; continue; fi + temp_out="$TMP/$file.view" + cat "$file" | python -m json.tool > "$temp_out" + show_list+=($temp_out) + test_or_continue "pretty printing '$file'" + done + filedump "${show_list[@]}" + rm "${show_list[@]}" + } + ############## # NOTE: no more function definitions are allowed after this point.