-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Until now the REPL executed the shell command once, and you could not reload the json. Now if you hit Ctrl+R the shell command is re-run and you can see the preview with the updated JSON input.
- Loading branch information
Showing
4 changed files
with
38 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/usr/bin/env jq -r -f | ||
# path logic inspired by https://github.com/stedolan/jq/issues/243 | ||
[ | ||
path(..) | | ||
map(select(type=="string") // "[]") | | ||
join(".") | split(".[]") | join("[]") | ||
] | map("." + .) | unique | .[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,33 @@ | ||
#!/bin/sh | ||
if [ -z "$1" ] || [ "$1" = "-" ]; then | ||
input=$(mktemp) | ||
trap 'rm -f "$input"' EXIT | ||
cat /dev/stdin > "$input" | ||
# | ||
# if 1st arg is '-' read from stdin | ||
# if 1st arg is '--' take the command after it verbatim and execute it to get the input | ||
# if 1st arg is anything else, treat it as a file | ||
set -eu | ||
|
||
if [ -n "${1:-}" ] && [ "$1" != "-" ] && [ "$1" != "--" ]; then | ||
input="$1" | ||
else | ||
input=$(mktemp) | ||
trap 'rm -f "$input"' EXIT | ||
fi | ||
|
||
if [ -z "${1:-}" ] || [ "$1" = "-" ]; then | ||
cat /dev/stdin >"$input" | ||
fi | ||
if [ "${1:-}" = "--" ]; then | ||
shift | ||
export FZF_JQ_REPL_COMMAND="$* > $input; jq-paths <$input" | ||
else | ||
input="$1" | ||
export FZF_JQ_REPL_COMMAND="jq-paths < $input" | ||
fi | ||
|
||
# path logic inspired by https://github.com/stedolan/jq/issues/243 | ||
<"$input" jq -r '[ | ||
path(..) | | ||
map(select(type=="string") // "[]") | | ||
join(".") | split(".[]") | join("[]") | ||
] | map("." + .) | unique | .[]' | | ||
fzf \ | ||
--preview "jq --color-output $JQ_REPL_ARGS {q} \"$input\"" \ | ||
eval "$FZF_JQ_REPL_COMMAND" | | ||
fzf \ | ||
--preview "jq --color-output ${JQ_REPL_ARGS:-} {q} \"$input\"" \ | ||
--preview-window="down:90%" \ | ||
--height="99%" \ | ||
--query="." \ | ||
--bind "tab:replace-query,return:print-query" \ | ||
--bind "alt-up:preview-page-up,alt-down:preview-page-down" | ||
--bind "alt-up:preview-page-up,alt-down:preview-page-down" \ | ||
--bind "ctrl-r:reload($FZF_JQ_REPL_COMMAND)+refresh-preview" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
if [[ -o zle ]]; then | ||
|
||
__get_query() { | ||
eval "$LBUFFER" | jq-repl | ||
jq-repl -- ${LBUFFER} | ||
return $? | ||
} | ||
|
||
|