Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/reegnz/jq-zsh-plugin
jq zsh plugin
https://github.com/reegnz/jq-zsh-plugin
cli fzf jq shell zsh zsh-plugin zshell
Last synced: about 2 months ago
JSON representation
jq zsh plugin
- Host: GitHub
- URL: https://github.com/reegnz/jq-zsh-plugin
- Owner: reegnz
- License: mit
- Created: 2020-01-29T16:53:31.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-04-11T10:29:26.000Z (about 2 months ago)
- Last Synced: 2024-04-11T11:34:49.255Z (about 2 months ago)
- Topics: cli, fzf, jq, shell, zsh, zsh-plugin, zshell
- Language: Shell
- Homepage:
- Size: 27.3 KB
- Stars: 293
- Watchers: 7
- Forks: 16
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Lists
- awesome-zsh-plugins - jq - Interactively build [jq](https://stedolan.github.io/jq/) expressions. Also supports [gojq](https://github.com/itchyny/gojq). Requires [fzf](https://github.com/junegunn/fzf). (Plugins / ZSH on Windows)
- awesome-from-stars - reegnz/jq-zsh-plugin
- awesome-stars - jq-zsh-plugin
- awesome-stars - reegnz/jq-zsh-plugin - jq zsh plugin (Shell)
- fucking-awesome-zsh-plugins - jq - Interactively build đ [jq](stedolan.github.io/jq/) expressions. Also supports <b><code> 3125â</code></b> <b><code> 114đ´</code></b> [gojq](https://github.com/itchyny/gojq)). Requires <b><code> 60791â</code></b> <b><code> 2315đ´</code></b> [fzf](https://github.com/junegunn/fzf)). (Plugins / ZSH on Windows)
- awesome-zsh-plugins - jq - repl with line editor functionality. (Plugins / Zinit (nÊe zplugin))
- awesome-zsh-plugins - jq - Interactively build [jq](https://stedolan.github.io/jq/) expressions. (Plugins / ZSH on Windows)
README
# jq zsh plugin
Interactively build [jq](https://stedolan.github.io/jq/) expressions
([gojq](https://github.com/itchyny/gojq) is also supported).This zsh plugin gives you jq superpowers!
[Fish](https://fishshell.com/) users: you can use this friendly fork: [rmartine-ias/jq-fish-plugin](https://github.com/rmartine-ias/jq-fish-plugin)
## Table of contents
- [Demos](#demos)
- [Installation](#installation)
- [Usage](#usage)
- [Key bindings](#key-bindings)## Demos
### Interactive jq query construction
[![asciicast](https://asciinema.org/a/IqAqzPS0ZgeaduQ3qs1B5ZgRI.svg)](https://asciinema.org/a/IqAqzPS0ZgeaduQ3qs1B5ZgRI)
### Insert jq query in the middle of a pipeline
[![asciicast](https://asciinema.org/a/9Q4Va21OzD2VTbHwntmLWGvm6.svg)](https://asciinema.org/a/9Q4Va21OzD2VTbHwntmLWGvm6)
## Installation
Besides [jq](https://stedolan.github.io/jq/), this plugin also requires
[fzf](https://github.com/junegunn/fzf#installation) ([a recent version](https://github.com/reegnz/jq-zsh-plugin/issues/19)) to be installed and available on your
PATH.The following installation methods are proven to work:
* [Oh My Zsh](#oh-my-zsh)
* [zplug](#zplug)
* [Antigen](#antigen)
* [Zgen](#zgen)### [Oh My Zsh](https://ohmyz.sh)
1. Clone the repository:
```sh
git clone https://github.com/reegnz/jq-zsh-plugin.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/jq
```2. Add the plugin to the list of plugins for Oh My Zsh to load (inside `~/.zshrc`):
```sh
plugins=(
# other plugins...
jq
)
```3. Start a new terminal session.
### [zplug](https://github.com/zplug/zplug)
```sh
zplug reegnz/jq-zsh-plugin
```### [Antigen](https://github.com/zsh-users/antigen)
```sh
antigen bundle reegnz/jq-zsh-plugin
```### [Zgen](https://github.com/tarjoilija/zgen)
```sh
zgen load reegnz/jq-zsh-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](https://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop)!)
- 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](https://github.com/itchyny/gojq) then you can override the default jq
command used by the plugin. Set the following environment variable:```sh
JQ_REPL_JQ=gojq
```## Internals
The project consists of the following components:
- a `jq.plugin.zsh` providing a [user-defined zsh line-editor
widget](https://zsh.sourceforge.io/Doc/Release/Zsh-Line-Editor.html),
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/205318Another option is to map to `ctrl+j` instead by putting this in your `.zshrc`:
```sh
bindkey `^j` jq-complete
```### Disable expanding shell aliases
The plugin automatically expands shell aliases in a command before passing it
to `jq-repl`. To disable, put the following line into your `.zshrc`:```sh
JQ_ZSH_PLUGIN_EXPAND_ALIASES=0
```