From 85238428377c031db634eecd468ec1e3e5628324 Mon Sep 17 00:00:00 2001 From: jessebot Date: Thu, 2 Jan 2025 13:36:19 +0100 Subject: [PATCH] catch any errors we might get from yq trying to render gotemplated files --- .config/bash/text_editing.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.config/bash/text_editing.sh b/.config/bash/text_editing.sh index 647a6a9..1ebc1a8 100644 --- a/.config/bash/text_editing.sh +++ b/.config/bash/text_editing.sh @@ -75,16 +75,17 @@ bat cache --build > /dev/null || batcat cache --build > /dev/null function dog { # if this is a csv file, ALWAYS use rich to print the data if [[ "$1" == *".csv" ]]; then - rich $1 + rich "$1" # if this is a json file, always use jq to pretty print it elif [[ "$1" == *".json" ]]; then - env cat $1 | jq + env cat "$1" | jq # if this is a YAML file, always use yq to pretty print and validate it + # if using yq fails, fall back to bat & redirect errors to the shadow realm elif [[ "$1" == *".yaml" ]] || [[ "$1" == *".yml" ]]; then - env cat $1 | yq + env cat "$1" | yq 2> /dev/null || bat --plain --theme=spacechalk --pager=never "$1" else # use batcat - syntax highlighting + git support - bat --plain --theme=spacechalk --pager=never $1 || batcat --pager=never --theme=spacechalk --plain $1 + bat --plain --theme=spacechalk --pager=never "$1" || batcat --pager=never --theme=spacechalk --plain "$1" fi }