Skip to content

rmartine-ias/jq-fish-plugin

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 

Repository files navigation

jq fish plugin

Interactively build jq expressions (gojq is also supported).

This fish plugin gives you jq superpowers! (See also: upstream zsh plugin.)

This fish fork is not as well tested yet!

Table of contents

Demos

Interactive jq query construction

asciicast

Insert jq query in the middle of a pipeline

asciicast

Installation

Besides jq, this plugin also requires fzf (a recent version) to be installed and available on your PATH.

For automatic yaml support, install gojq as well.

fisher install rmartine-ias/jq-fish-plugin

Usage

  • type out a command that you expect to produce json on its standard output
  • press alt + j
  • start typing jq expression and watch it being evaluated in real time (like a true REPL!)
  • use up/down and hit tab to select one of the suggestions
  • or type out a jq query on your own
  • press enter, and the jq expression is appended to your initial command!

Key bindings

Bringing up the jq query builder for a shell command: alt + j

During interactive querying, the following shortcuts can be used:

Shortcut Effect
up Navigate path queries
down Navigate path queries
tab Select path query
shift + up Scroll up
shift + down Scroll down
alt + up Scroll up full page
alt + down Scroll down full page
ctrl+r Reload input

gojq support

If you want to use an alternative jq implementation, like gojq then you can override the default jq command used by the plugin. Set the following environment variable:

JQ_REPL_JQ=gojq

Internals

The project consists of the following components:

  • a fish plugin providing a line-editor widget, utilizing the jq-repl command
  • a jq-repl command to interactively build jq expressions, utilizing fzf for its UI
  • a jq-paths command to get all valid jq paths in the provided JSON document, used for suggesting paths.

Troubleshooting

MacOS: Pressing alt-j creates a symbol in iTerm2

You need to remap your alt-key to Esc+ in iTerm2:

  • Cmd + , to enter preferences
  • Go to Profiles
  • select your profile from the pane on the left hand side
  • go to the keys tab
  • Set Left Option (⌥ ) Key to Esc+

See other suggestions on stackoverflow if the above one doesn't help you: https://stackoverflow.com/q/196357/205318

Another option is to map to ctrl+j instead by putting this in your .zshrc:

bindkey `^j` jq-complete

About

jq repl fish plugin

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Shell 100.0%