# rlwrap
### WHAT IT IS
`rlwrap` is a readline wrapper, a small utility that uses the [GNU Readline](https://tiswww.case.edu/php/chet/readline/rltop.html) library to allow the editing of keyboard input for any command.
### INSTALLATION:
- Unix-like systems
```bash=
brew install rlwrap
pkg install rlwrap
```
### HOW TO USE IT:
If
```
$ <command> <args>
```
displays the infamous ^[[D when you press a left arrow key, or if you just want decent input history and completion, try:
```
$ rlwrap [-options] <command> <args>
```
### REFERENCE
https://github.com/hanslub42/rlwrap
# jq
### WHAT IT IS
jq is like `sed` for JSON data - you can use it to slice and filter and map and transform structured data with the same ease that `sed`, `awk`, `grep` and friends let you play with text.
### INSTALLATION:
- Linux
- MacOS `brew install jq`
- FreeBSD `pkg install jq`
- Solaris
- Windows
### HOW TO USE IT:
GitHub has a JSON API, so let's play with that. This URL gets us the last 5 commits from the jq repo.
```
curl 'https://api.github.com/repos/stedolan/jq/commits?per_page=5'
```
GitHub returns nicely formatted JSON. For servers that don't, it can be helpful to pipe the response through jq to pretty-print it. The simplest jq program is the expression `.`, which takes the input and produces it unchanged as output.
```
curl 'https://api.github.com/repos/stedolan/jq/commits?per_page=5' | jq '.'
```
We can use jq to extract just the first commit.
```
curl 'https://api.github.com/repos/stedolan/jq/commits?per_page=5' | jq '.[0]'
```
For the rest of the examples, I'll leave out the `curl` command - it's not going to change.
There's a lot of info we don't care about there, so we'll restrict it down to the most interesting fields.
```
jq '.[0] | {message: .commit.message, name: .commit.committer.name}'
```
The `|` operator in jq feeds the output of one filter (`.[0]` which gets the first element of the array in the response) into the input of another (`{...}` which builds an object out of those fields). You can access nested attributes, such as `.commit.message`.
Now let's get the rest of the commits.
```
jq '.[] | {message: .commit.message, name: .commit.committer.name}'
```
`.[]` returns each element of the array returned in the response, one at a time, which are all fed into `{message: .commit.message, name: .commit.committer.name}`.
Data in jq is represented as streams of JSON values - every jq expression runs for each value in its input stream, and can produce any number of values to its output stream.
Streams are serialised by just separating JSON values with whitespace. This is a `cat`-friendly format - you can just join two JSON streams together and get a valid JSON stream.
If you want to get the output as a single array, you can tell jq to "collect" all of the answers by wrapping the filter in square brackets:
```
jq '[.[] | {message: .commit.message, name: .commit.committer.name}]'
```
### REFERENCE
https://stedolan.github.io/jq/