Skip to content

Commit

Permalink
Convert jqjq output to raw
Browse files Browse the repository at this point in the history
  • Loading branch information
thaliaarchi committed Nov 2, 2024
1 parent e610f6b commit 921f128
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions wsjqjq
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ check_clean=false
check_retrieve=false
print_pc=false
jq=jq
jqjq=jqjq
jqjq="$(which jqjq || echo jqjq)"

while getopts ':hi:e:ncrp-:' optchar; do
case "$optchar" in
Expand Down Expand Up @@ -119,6 +119,7 @@ if [[ ! "$jq" == *gojq ]]; then
fi

jqjq="${jqjq/#\~/$HOME}"
jqjq_dir="$(dirname "$(realpath "$jqjq")")"

# jqjq does not support environment args, so quote them with jq.
env="$("$jq" -nr \
Expand Down Expand Up @@ -151,6 +152,14 @@ $(cat "$SCRIPT_DIR/ws.jq")
$(sed '/^include /d' "$SCRIPT_DIR/main.jq")"

# Quote inputs with jq, to work around jqjq not having -R.
"$jq" -nR "${jq_options[@]}" inputs |
"$jqjq" --jq "$jq" -n "$program"
# Directly invoke jqjq.jq, to pass --raw-input (-R) and --unbuffered to jq.
# jqjq doesn't yet support --join-output (-j), so it needs to be piped to
# another jq instance, which post-processes it. jq defaults to buffered output,
# when it is piped, and needs overriding.
"$jq" -nrR "${jq_options[@]}" \
-L "$jqjq_dir" \
--args 'include "jqjq"; jqjq($ARGS.positional; $ENV)' \
-- \
-M \
-n "$program" |
"$jq" -nj "${jq_options[@]}" inputs

0 comments on commit 921f128

Please sign in to comment.