Skip to content

Commit

Permalink
Add gojq support
Browse files Browse the repository at this point in the history
  • Loading branch information
reegnz committed May 10, 2022
1 parent 9de99b0 commit 535fb66
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion bin/jq-paths
Original file line number Diff line number Diff line change
@@ -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("[]") | "." + .
'
4 changes: 3 additions & 1 deletion bin/jq-repl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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="." \
Expand Down
2 changes: 1 addition & 1 deletion jq.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 535fb66

Please sign in to comment.