diff --git a/README.md b/README.md index 2fea03a..7ee59c0 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,16 @@ During interactive querying, the following shortcuts can be used: | `alt + down` | Scroll down full page | | `ctrl+r` | Reload input | + +## gojq support + +If you want to use an alternative `jq` implementation, like +[gojq](https://github.com/itchyny/gojq) then you can override the default jq +command used by the plugin, by setting the following environment variable: +```sh +JQ_REPL_JQ=gojq +``` + ## Demos ### Interactive jq query construction diff --git a/bin/jq-paths b/bin/jq-paths index e3f7145..3d0d51a 100755 --- a/bin/jq-paths +++ b/bin/jq-paths @@ -1,6 +1,9 @@ -#!/usr/bin/env -S jq -r -f +#!/bin/sh # path logic inspired by https://github.com/stedolan/jq/issues/243 +JQ_REPL_JQ="${JQ_REPL_JQ:-jq}" +$JQ_REPL_JQ -r ' [ path(..) | map(select(type == "string") // "[]") | join(".") ] | sort | unique | .[] | split(".[]") | join("[]") | "." + . +' diff --git a/bin/jq-repl b/bin/jq-repl index 3131514..2ca6289 100755 --- a/bin/jq-repl +++ b/bin/jq-repl @@ -5,6 +5,8 @@ # if 1st arg is anything else, treat it as a file set -eu +JQ_REPL_JQ="${JQ_REPL_JQ:-jq}" + if [ -n "${1:-}" ] && [ "$1" != "-" ] && [ "$1" != "--" ]; then input="$1" else @@ -32,7 +34,7 @@ fi eval "$FZF_JQ_REPL_COMMAND" | fzf \ - --preview "jq --color-output ${JQ_REPL_ARGS:-} {q} \"$input\"" \ + --preview "$JQ_REPL_JQ --color-output ${JQ_REPL_ARGS:-} {q} \"$input\"" \ --preview-window="down:90%" \ --height="99%" \ --query="." \ diff --git a/jq.plugin.zsh b/jq.plugin.zsh index 4f81d60..eec2799 100755 --- a/jq.plugin.zsh +++ b/jq.plugin.zsh @@ -17,7 +17,7 @@ jq-complete() { local query="$(__get_query)" local ret=$? if [ -n "$query" ]; then - LBUFFER="${LBUFFER} | jq" + LBUFFER="${LBUFFER} | ${JQ_REPL_JQ:-jq}" [[ -z "$JQ_REPL_ARGS" ]] || LBUFFER="${LBUFFER} ${JQ_REPL_ARGS}" LBUFFER="${LBUFFER} '$query'" fi