Compare commits

..

No commits in common. "fix/bash3-compat" and "main" have entirely different histories.

View file

@ -70,24 +70,19 @@ function infracost_breakdown_ {
# -h .totalHourlyCost > 0.1
# --hook-config=.currency == "USD"
first_char=${check:0:1}
last_char=${check:$((${#check} - 1)):1}
last_char=${check: -1}
if [ "$first_char" == "$last_char" ] && {
[ "$first_char" == '"' ] || [ "$first_char" == "'" ]
}; then
check="${check:1:$((${#check} - 2))}"
check="${check:1:-1}"
fi
# Replace mapfile with while read loop for bash 3.2 compatibility
operations=()
while IFS= read -r line; do
operations+=("$line")
done < <(echo "$check" | grep -oE '[!<>=]{1,2}')
mapfile -t operations < <(echo "$check" | grep -oE '[!<>=]{1,2}')
# Get the very last operator, that is used in comparison inside `jq` query.
# From the example below we need to pick the `>` which is in between `add` and `1000`,
# but not the `!=`, which goes earlier in the `jq` expression
# [.projects[].diff.totalMonthlyCost | select (.!=null) | tonumber] | add > 1000
operation=${operations[$((${#operations[@]} - 1))]}
operation=${operations[-1]}
IFS="$operation" read -r -a jq_check <<< "$check"
real_value="$(jq "${jq_check[0]}" <<< "$RESULTS")"