-
-
Save Profpatsch/b639e9a11e64f1db82130b9075b9ac2b to your computer and use it in GitHub Desktop.
jq replacement (‽)
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/bin/env bash | |
if [[ -z "$1" ]]; then | |
echo "No filter given, abort" | |
exit 1 | |
fi | |
tmp=$(mktemp -d) | |
jq="$tmp/jq" | |
cat > "$jq" <<EOF | |
#!/usr/bin/env nix-shell | |
#!nix-shell -i runhaskell -p 'haskellPackages.ghcWithPackages (h: [ h.lens-aeson h.lens h.safe h.protolude ])' | |
{-# LANGUAGE OverloadedStrings, NoImplicitPrelude #-} | |
import Protolude | |
import Data.String (String) | |
import Data.Aeson | |
import Data.Aeson.Lens | |
import Control.Lens | |
import System.FilePath.Lens | |
import System.Environment (getArgs) | |
import qualified Data.ByteString as B | |
import qualified Data.ByteString.Lazy as BL | |
main = do | |
data_ <- BL.getContents | |
let out = case (eitherDecode' data_ :: Either String Value) of | |
Left err -> panic $ "decoding failed: " <> toS err | |
Right val -> userProgram val | |
BL.putStr $ encode (out :: Value) | |
userProgram = | |
EOF | |
echo "$1" | sed 's/^/ /' >> "$jq" | |
chmod +x "$jq" | |
"$jq" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: