Skip to content

Commit

Permalink
Properly escape $1 and make jq-repl more POSIX-ish
Browse files Browse the repository at this point in the history
mktemp is still an issue as it's not POSIX, but for now
I'm assuming is wide-spread enough to not cause any big issues.

See #8 for why not bash or sh instead of zsh.
  • Loading branch information
reegnz committed Aug 30, 2021
1 parent 1774940 commit 98650d6
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions bin/jq-repl
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env bash
if [[ -z $1 ]] || [[ $1 == "-" ]]; then
#!/bin/sh
if [ -z "$1" ] || [ "$1" = "-" ]; then
input=$(mktemp)
trap "rm -f $input" EXIT
cat /dev/stdin > $input
trap 'rm -f "$input"' EXIT
cat /dev/stdin > "$input"
else
input=$1
input="$1"
fi

# path logic inspired by https://github.com/stedolan/jq/issues/243
Expand All @@ -14,7 +14,7 @@ fi
join(".") | split(".[]") | join("[]")
] | map("." + .) | unique | .[]' |
fzf \
--preview "jq --color-output $JQ_REPL_ARGS {q} $input" \
--preview "jq --color-output $JQ_REPL_ARGS {q} \"$input\"" \
--preview-window="down:90%" \
--height="99%" \
--query="." \
Expand Down

0 comments on commit 98650d6

Please sign in to comment.