Search code examples
jsonbashsublimetext3sublimetextpretty-print

Launch Sublime Text from CLI, paste text from stdin and Pretty Print JSON


From OS X 10.11.3 Terminal (bash shell), I want to open a JSON string in Sublime Text 3 and use the Pretty JSON package to "Pretty Print" the JSON string to a better readable format.

According to Sublime Text 3 documentation, it should be possible to specify commands from the CLI using the --command parameter.

The following command manages to open the JSON string in Sublime Text 3. It fails to Pretty Print the JSON string.

echo "{ "menu": { "id": "file", "value": "File" }}" | subl --command jq_pretty_json -

Does anybody know how I can apply this Pretty Print command from the OS X command line? When calling the Pretty JSON from the Sublime Text 3 UI, it works without problems.


Solution

  • The following command manages to do what I want:

    echo '{ "menu": { "id": "file", "value": "File" }}' | subl - & sleep 1; subl --command pretty_json