Skip to content

Commit 535fb66

Browse files
committed
Add gojq support
1 parent 9de99b0 commit 535fb66

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,16 @@ During interactive querying, the following shortcuts can be used:
6565
| `alt + down` | Scroll down full page |
6666
| `ctrl+r` | Reload input |
6767

68+
69+
## gojq support
70+
71+
If you want to use an alternative `jq` implementation, like
72+
[gojq](https://github.com/itchyny/gojq) then you can override the default jq
73+
command used by the plugin, by setting the following environment variable:
74+
```sh
75+
JQ_REPL_JQ=gojq
76+
```
77+
6878
## Demos
6979

7080
### Interactive jq query construction

bin/jq-paths

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
#!/usr/bin/env -S jq -r -f
1+
#!/bin/sh
22
# path logic inspired by https://github.com/stedolan/jq/issues/243
3+
JQ_REPL_JQ="${JQ_REPL_JQ:-jq}"
4+
$JQ_REPL_JQ -r '
35
[
46
path(..) | map(select(type == "string") // "[]")
57
| join(".")
68
] | sort | unique | .[] | split(".[]") | join("[]") | "." + .
9+
'

bin/jq-repl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
# if 1st arg is anything else, treat it as a file
66
set -eu
77

8+
JQ_REPL_JQ="${JQ_REPL_JQ:-jq}"
9+
810
if [ -n "${1:-}" ] && [ "$1" != "-" ] && [ "$1" != "--" ]; then
911
input="$1"
1012
else
@@ -32,7 +34,7 @@ fi
3234

3335
eval "$FZF_JQ_REPL_COMMAND" |
3436
fzf \
35-
--preview "jq --color-output ${JQ_REPL_ARGS:-} {q} \"$input\"" \
37+
--preview "$JQ_REPL_JQ --color-output ${JQ_REPL_ARGS:-} {q} \"$input\"" \
3638
--preview-window="down:90%" \
3739
--height="99%" \
3840
--query="." \

jq.plugin.zsh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jq-complete() {
1717
local query="$(__get_query)"
1818
local ret=$?
1919
if [ -n "$query" ]; then
20-
LBUFFER="${LBUFFER} | jq"
20+
LBUFFER="${LBUFFER} | ${JQ_REPL_JQ:-jq}"
2121
[[ -z "$JQ_REPL_ARGS" ]] || LBUFFER="${LBUFFER} ${JQ_REPL_ARGS}"
2222
LBUFFER="${LBUFFER} '$query'"
2323
fi

0 commit comments

Comments
 (0)