Skip to content

Instantly share code, notes, and snippets.

@homam
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save homam/a582dc2f0f16ca43c99b to your computer and use it in GitHub Desktop.
Save homam/a582dc2f0f16ca43c99b to your computer and use it in GitHub Desktop.
Alternative to jq CLI tool using LiveScript
#!/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)
@urzhumskov
Copy link

You could simply import everything from prelude-ls to global scope like this:

global <<< require \prelude-ls

@homam
Copy link
Author

homam commented Sep 11, 2014

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