From 2c1c0c8a4f151d4b75c62db65dd9a5cadc753cc4 Mon Sep 17 00:00:00 2001 From: Chris Koeritz Date: Tue, 7 Nov 2017 23:06:38 -0500 Subject: [PATCH] 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. --- scripts/core/functions.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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. -- 2.34.1