Last active
August 29, 2015 14:05
-
-
Save homam/a582dc2f0f16ca43c99b to your computer and use it in GitHub Desktop.
Alternative to jq CLI tool using LiveScript
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
#!/usr/local/bin/lsc -d | |
# example: echo "[1,2,3,4,5]" | ./jqlsc.ls "sum . map (+ 2)" | |
{each, obj-to-pairs} = require \prelude-ls | |
lsc = require \LiveScript | |
global <<< require \prelude-ls | |
trim = -> if it[*-1] == \; then it.substr 0, it.length - 1 else it | |
stdin = process.openStdin! | |
code = process.argv.2 | |
input = "" | |
stdin.on \data, (data) -> | |
input += data if data is not null | |
stdin.on \end, -> | |
compiled = lsc.compile code, bare: true | |
compiled = "(#{trim compiled})(#input)" | |
process.stdout.write <| eval compiled |> (-> JSON.stringify it, null, 4) |> (+ \\n) |
Color output:
| underscore print --color
| pygmentize -l javascript
| pjson
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You could simply import everything from
prelude-ls
to global scope like this: