From 3f813a65b0d41b4a1771349f27a2d0ccafb740f5 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Wed, 19 Jan 2011 11:36:19 +0000 Subject: =?UTF-8?q?=E2=80=A2=20improved=20replacing=20selection=20of=20Bun?= =?UTF-8?q?dle=20commands=20-=20intersect=20ranges=20in=20beforehand=20for?= =?UTF-8?q?=20safety=20reasons=20=E2=80=A2=20removed=20Serialize/Prettify?= =?UTF-8?q?=20JSON=20Bundles=20by=20Toggle=20JSON=20Format=20which=20auto-?= =?UTF-8?q?detects=20the=20JSON=20format=20to=20decide=20whether=20to=20se?= =?UTF-8?q?rialize=20or=20pretty=20print?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Toggle JSON Format.spBundle/command.plist | 68 ++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 SharedSupport/Default Bundles/Toggle JSON Format.spBundle/command.plist (limited to 'SharedSupport/Default Bundles/Toggle JSON Format.spBundle/command.plist') diff --git a/SharedSupport/Default Bundles/Toggle JSON Format.spBundle/command.plist b/SharedSupport/Default Bundles/Toggle JSON Format.spBundle/command.plist new file mode 100644 index 00000000..6476d86b --- /dev/null +++ b/SharedSupport/Default Bundles/Toggle JSON Format.spBundle/command.plist @@ -0,0 +1,68 @@ + + + + + author + Hans-Jörg Bibiko + category + Format + command + DATA=$(cat) + +FORMAT=$(echo "$DATA" | head -n 1 | perl -e '$l=<>;print "1" if($l=~m/^\s*\{\s*$/)') + +# if FORMAT == 1 then serialize JSON data otherwise pretty print them +if [ "$FORMAT" == 1 ]; then + + DATA=$(echo "$DATA" | php -r ' + $jsonData = ""; + $inputStream = fopen("php://stdin", "r"); + while($d = fgets($inputStream)) { $jsonData .= $d; } + print json_encode(json_decode($jsonData)); + ') + +else + + DATA=$(echo "$DATA" | python -mjson.tool) + +fi + +# if there's a need to preserve Unicode characters remove the first to characters of the following line +# DATA=$(echo "$DATA" | perl -Xpe 'binmode STDIN,":utf8";binmode STDOUT,":utf8";s/\\u([0-9A-F]{4})/chr(hex($1))/ieg') + +echo "$DATA" + contact + znvy@ovovxb.qr + description + If the first line of the selection or the entire content of the current text input field only contains a "{" then serialize the JSON data otherwise the JSON data will be pretty printed. If there's a need to preserve the Unicode characters you can uncomment the line 22. + +Version 1.0 + input + selectedtext + input_fallback + entirecontent + internalKeyEquivalent + + characters + J + keyCode + 38 + modifierFlags + 1572864 + + keyEquivalent + ~@j + name + Toggle JSON Format + output + replaceselection + scope + inputfield + tooltip + Serialize or pretty print JSON data + uuid + 87FD8A4F-90AA-4020-9E0B-8CDD05764D08 + isDefaultBundle + + + -- cgit v1.2.3