diff options
Diffstat (limited to 'SharedSupport')
8 files changed, 750 insertions, 0 deletions
diff --git a/SharedSupport/Default Bundles/CopyAsJSON.spBundle/command.plist b/SharedSupport/Default Bundles/CopyAsJSON.spBundle/command.plist new file mode 100644 index 00000000..f4f1ecd9 --- /dev/null +++ b/SharedSupport/Default Bundles/CopyAsJSON.spBundle/command.plist @@ -0,0 +1,132 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> +<dict> + <key>author</key> + <string>Hans-Jörg Bibiko</string> + <key>category</key> + <string>Copy</string> + <key>command</key> + <string>cat | perl -e ' + +# read first line to get the column names (header) +$firstLine = <>; + +# bail if nothing could read +if(!defined($firstLine)) { + exit 0; +} + +# store the column names +chomp($firstLine); +$firstLine =~ s/\"/\\\"/g; # escape " +@header = split(/\t/, $firstLine); + +$h_cnt = $#header; # number of columns + +# get the column definitions +open(META, $ENV{"SP_BUNDLE_INPUT_TABLE_METADATA"}) or die $!; +@meta = (); +while(<META>) { + chomp(); + my @arr = split(/\t/); + push @meta, \@arr; +} +close(META); + +print "{\n\t\"data\":\n\t[\n"; + +# read row data of each selected row +$rowData=<>; +while($rowData) { + + print "\t\t{\n"; + + # remove line ending + chomp($rowData); + + # escape " + $rowData=~s/\"/\\\"/g; + + # split column data which are tab-delimited + @data = split(/\t/, $rowData); + for($i=0; $i<=$h_cnt; $i++) { + + # re-escape \t and \n + $cellData = $data[$i]; + $cellData =~ s/↵/\n/g; + $cellData =~ s/⇥/\t/g; + + print "\t\t\t\"$header[$i]\": "; + + # check for data types + if($cellData eq "NULL") { + print "null"; + } + elsif($meta[$i]->[1] eq "integer" || $meta[$i]->[1] eq "float") { + chomp($cellData); + $d = $cellData+0; + print "$d"; + } else { + chomp($cellData); + print "\"$cellData\""; + } + + # suppress last , + if($i<$h_cnt) { + print ","; + } + + print "\n"; + + } + + print "\t\t}"; + + # get next row + $rowData=<>; + + # suppress last , + if($rowData) { + print ","; + } + + print "\n"; +} + +print "\t]\n}"; + +' | __CF_USER_TEXT_ENCODING=$UID:0x8000100:0x8000100 pbcopy</string> + <key>contact</key> + <string>znvy@ovovxb.qr</string> + <key>description</key> + <string>Copies the selected rows excluding any BLOB data in a data table JSON formatted into the pasteboard. + +Version 1.0</string> + <key>input</key> + <string>selectedtablerowsastab</string> + <key>internalKeyEquivalent</key> + <dict> + <key>characters</key> + <string>C</string> + <key>keyCode</key> + <integer>8</integer> + <key>modifierFlags</key> + <integer>262144</integer> + </dict> + <key>keyEquivalent</key> + <string>^c</string> + <key>name</key> + <string>Copy as JSON</string> + <key>output</key> + <string>none</string> + <key>scope</key> + <string>datatable</string> + <key>tooltip</key> + <string>Copies the selected rows excluding any BLOB data JSON formatted into the pasteboard</string> + <key>uuid</key> + <string>CBB8B7A7-5AB9-4F4C-A404-D99CA9521337</string> + <key>isDefaultBundle</key> + <true/> +</dict> +</plist> diff --git a/SharedSupport/Default Bundles/CopySingleLineQuoted.spBundle/command.plist b/SharedSupport/Default Bundles/CopySingleLineQuoted.spBundle/command.plist new file mode 100644 index 00000000..56cdd9c4 --- /dev/null +++ b/SharedSupport/Default Bundles/CopySingleLineQuoted.spBundle/command.plist @@ -0,0 +1,49 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> +<dict> + <key>author</key> + <string>Hans-Jörg Bibiko</string> + <key>category</key> + <string>Query Editor</string> + <key>command</key> + <string>cat | perl -ne 'chomp;s/\t/ /g;s/"/\\"/g;print "\"".$_."\" . \"\\n\" .\n"' | sed '$ s/.........$//' | sed '$ s/$/;/' | __CF_USER_TEXT_ENCODING=$UID:0x8000100:0x8000100 pbcopy</string> + <key>contact</key> + <string>znvy@ovovxb.qr</string> + <key>description</key> + <string>Takes the current query or the selection and copies it as a single line quoted multi-line string by appending a ; into the pasteboard for usage in other IDEs as e.g. PHP code snippet. + +Example: + +SELECT a + FROM b + ORDER BY c DESC + +will copy + +"SELECT a" . "\n" . +" FROM b" . "\n" . +" ORDER BY c DESC"; + +Version 1.0 +</string> + <key>input</key> + <string>selectedtext</string> + <key>input_fallback</key> + <string>currentquery</string> + <key>keyEquivalent</key> + <string></string> + <key>name</key> + <string>Copy Single Line Quoted</string> + <key>output</key> + <string>none</string> + <key>scope</key> + <string>inputfield</string> + <key>tooltip</key> + <string>Takes the current query or the selection and copies it as a single line quoted multi-line string by appending a ; into the pasteboard</string> + <key>uuid</key> + <string>CDAC825A-AE80-4544-9DBB-8E68A5C540D0</string> + <key>isDefaultBundle</key> + <true/> +</dict> +</plist> diff --git a/SharedSupport/Default Bundles/DB Report.spBundle/Support/header.html b/SharedSupport/Default Bundles/DB Report.spBundle/Support/header.html new file mode 100644 index 00000000..b67b633c --- /dev/null +++ b/SharedSupport/Default Bundles/DB Report.spBundle/Support/header.html @@ -0,0 +1,41 @@ +<html> + <head> + <title>Database Report</title> + <style type="text/css"> + hr { + background: #606060; + color: #606060; + border-style: solid; + border-color: #606060; + border-width: 2px 0 0 0; + margin-top: 0; + } + a:hover { + text-decoration: none; + } + a { + text-decoration: none; + } + a:hover:after { + content: " ➪"; + } + .nonVisible { + display:none; + } + </style> + <script type="text/javascript" charset="utf-8"> + function toggle_display(elt) + { + var e; var p; + e = elt.getAttribute("id") + ":data"; + if (window.document.getElementById(e).className != "") { + window.document.getElementById(e).className = ""; + elt.innerHTML = "▼"; + } else { + window.document.getElementById(e).className = "nonVisible"; + elt.innerHTML = "▶"; + } + } + </script> + </head> +<body> diff --git a/SharedSupport/Default Bundles/DB Report.spBundle/Support/processTableData.pl b/SharedSupport/Default Bundles/DB Report.spBundle/Support/processTableData.pl new file mode 100755 index 00000000..7d0b5545 --- /dev/null +++ b/SharedSupport/Default Bundles/DB Report.spBundle/Support/processTableData.pl @@ -0,0 +1,32 @@ +#!/usr/bin/env perl -w + +while(<>) { + + # split tab delimited data + @data = split(/\t/); + + $pid = $ENV{"PID"}; + $db = $ENV{"DB"}; + $res = $ENV{"RES"}; + $itemType = "table"; + + # $data[1] is NULL indicates item is a view + if($data[1] eq "NULL") { + $img = "file://$res/table-view-small-square.tiff"; + $itemType = "view"; + } else { + $img = "file://$res/table-small-square.tiff"; + } + + print <<HTML4; + <tr> + <td align=center width='40px'><img src=\"$img\"></td> + <td><a href=\"sequelpro://$pid\@passToDoc/SelectDatabase/$db/$data[0]/\" title=\"Click to select $itemType “$db.$data[0]”\">$data[0]</a></td> + <td>$data[1]</td> + <td align=right>$data[4]</td> + <td align=right>$data[6]</td> + <td align=right>$data[11]</td> + <td align=right>$data[12]</td> + </tr> +HTML4 +}
\ No newline at end of file diff --git a/SharedSupport/Default Bundles/DB Report.spBundle/command.plist b/SharedSupport/Default Bundles/DB Report.spBundle/command.plist new file mode 100644 index 00000000..e6c808ae --- /dev/null +++ b/SharedSupport/Default Bundles/DB Report.spBundle/command.plist @@ -0,0 +1,174 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> +<dict> + <key>author</key> + <string>Hans-Jörg Bibiko</string> + <key>category</key> + <string>Report</string> + <key>command</key> + <string> +# Since this command will execute SQL statements at the front most +# document window's connection check for a passed process ID to cancel +# this command by displaying a tooltip. Otherwise the loop after +# “open "sequelpro://$SP_PROCESS_ID@passToDoc/ExecuteQuery"” +# won't break. +if [ -z $SP_PROCESS_ID ]; then + echo "<font color=red>No front most connection window found!</font>" + exit $SP_BUNDLE_EXIT_SHOW_AS_HTML_TOOLTIP +fi + +# send query to Sequel Pro +cat <<SQL > "$SP_QUERY_FILE" +SELECT TABLE_SCHEMA AS Name, FORMAT((SUM(DATA_LENGTH)+SUM(INDEX_LENGTH))/1000, 1) AS \`Size (kiB) incl. indices\` +FROM information_schema.TABLES +GROUP BY TABLE_SCHEMA +SQL + +# execute the SQL statement; the result will be available in the file $SP_QUERY_RESULT_FILE +open "sequelpro://$SP_PROCESS_ID@passToDoc/ExecuteQuery" + +# wait for Sequel Pro; status file will be written to disk if query was finished +while [ 1 ] +do + [[ -e "$SP_QUERY_RESULT_STATUS_FILE" ]] && break + sleep 0.01 +done + +# Prepair HTML code +cat "$SP_BUNDLE_PATH/Support/header.html" +cat <<HTML1 +<center> +<h3><font color=blue>Connection: ‘$SP_CURRENT_HOST’ – $SP_RDBMS_TYPE ($SP_RDBMS_VERSION)</font></h3> +<table width=80%> + <tr> + <td align=center><img width='96px' src='file://$SP_ICON_FILE'></td> + <td> + <table style='border-collapse:collapse'> + <tr> + <th align=left> +HTML1 + +# Check for possible MySQL error +if [ `cat "$SP_QUERY_RESULT_STATUS_FILE"` == 1 ]; then + + # If error + echo "<i>No global summary available</i>" + +else + + # $SP_QUERY_RESULT_FILE contains the file path to the query result + + # First line contains the column names - wrap them into <th> tags + cat "$SP_QUERY_RESULT_FILE" | head -n 1 |perl -pe 's!\t!</th><th></th><th align=right>!g;s!$!</th></tr><tr><td>!' + + # Output all row except the first one and wrap them into <tr><td> tags + cat "$SP_QUERY_RESULT_FILE" | sed '1d' | perl -pe 's!\t!</td><td>&nbsp;&nbsp;</td><td align='right'>!g;s!$!</tr><tr><td>!' + +fi +cat <<HTML2 + </table> + </td> + </tr> +</table> +<hr> +</center> +HTML2 + +# Clear hand-shake files for further usage +rm -f "$SP_QUERY_FILE" +rm -f "$SP_QUERY_RESULT_STATUS_FILE" +rm -f "$SP_QUERY_RESULT_FILE" +rm -f "$SP_QUERY_RESULT_META_FILE" + +# Read all databases into a BASH array; $SP_ALL_DATABASES provides them as a tab delimited string +# Set the Internal Field Separator IFS to 'tab' and process the array by using the new IFS due to +# the fact that a database name could contain 'spaces' +OLDIFS="$IFS" +IFS=" " +dbs=("$SP_ALL_DATABASES") + +# Loop through all databases +cnt=1 +for db in $dbs +do + + cat <<HTML3 + <br> + <table width=100% style='background-color:#ECECEC;'> + <tr> + <td width=20px><span id="$cnt" onclick=toggle_display(this) style="cursor:pointer;color:gray;font-size:smaller;" title="Toggle visibility">▼</span></td> + <td align=center width='40px'><img src='file://$SP_APP_RESOURCES_DIRECTORY/database-small.png'></td> + <td><big><a href='sequelpro://$SP_PROCESS_ID@passToDoc/SelectDatabase/$db' title='Click to select database “$db”'>$db</big></a></td> + </tr> + </table> + <table id="$cnt:data" border=1 style='border-collapse:collapse' width=100%> + <tr> + <th></th><th>Name</th><th>Engine</th><th>Rows</th><th>Size</th><th>Created</th><th>Updated</th> + </tr> +HTML3 + + # Query for table status + echo "SHOW TABLE STATUS IN \`$db\`" > "$SP_QUERY_FILE" + open "sequelpro://$SP_PROCESS_ID@passToDoc/ExecuteQuery" + + # wait for Sequel Pro; status file will be written to disk if query was finished + while [ 1 ] + do + [[ -e "$SP_QUERY_RESULT_STATUS_FILE" ]] && break + sleep 0.01 + done + + cnt=$((cnt+1)) + + export DB="$db" + export PID="$SP_PROCESS_ID" + export RES="$SP_APP_RESOURCES_DIRECTORY"; + cat "$SP_QUERY_RESULT_FILE" | sed '1d' | perl "$SP_BUNDLE_PATH/Support/processTableData.pl" + + echo "</table>" + + # Clear hand-shake files + rm -f "$SP_QUERY_FILE" + rm -f "$SP_QUERY_RESULT_STATUS_FILE" + rm -f "$SP_QUERY_RESULT_FILE" + rm -f "$SP_QUERY_RESULT_META_FILE" + +done + +# Reset IFS +IFS="$OLDIFS" + +echo "</body></html>" +</string> + <key>contact</key> + <string>znvy@ovovxb.qr</string> + <key>description</key> + <string>Display a report about all databases of the current connection including the possibility to select a database or table via hyperlink. + +Version 1.0</string> + <key>internalKeyEquivalent</key> + <dict> + <key>characters</key> + <string>A</string> + <key>keyCode</key> + <integer>0</integer> + <key>modifierFlags</key> + <integer>1835008</integer> + </dict> + <key>keyEquivalent</key> + <string>^~@a</string> + <key>name</key> + <string>Database Report</string> + <key>output</key> + <string>showashtml</string> + <key>scope</key> + <string>general</string> + <key>tooltip</key> + <string>Display report about all databases of the current connection</string> + <key>uuid</key> + <string>AC45C093-9157-4E18-9683-C94415995935</string> + <key>isDefaultBundle</key> + <true/> +</dict> +</plist> diff --git a/SharedSupport/Default Bundles/Format SQL.spBundle/command.plist b/SharedSupport/Default Bundles/Format SQL.spBundle/command.plist new file mode 100644 index 00000000..13e86145 --- /dev/null +++ b/SharedSupport/Default Bundles/Format SQL.spBundle/command.plist @@ -0,0 +1,203 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> +<dict> + <key>author</key> + <string>Hans-Jörg Bibiko</string> + <key>category</key> + <string>Format</string> + <key>command</key> + <string> + +# check for empty STDIN +SQL=$(cat) +if [ -z "$SQL" ]; then + echo "No SQL statements passed." + exit $SP_BUNDLE_EXIT_SHOW_AS_TEXT_TOOLTIP +fi + +# check if connected to the internet and if server is up +connected=$(/sbin/ping -t 8 -c 1 -on www.dpriver.com 2> /dev/null | grep '69\.5\.11\.169' | wc -l) +if [ $connected -eq "0" ]; then + echo "<font color=red>You are probably not connected to the internet or http://www.dpriver.com/ server is down.</font>" + exit $SP_BUNDLE_EXIT_SHOW_AS_HTML_TOOLTIP +fi + +# show info alert about sending the SQL statements to an online service +if [ ! -e infoShowed ]; then + touch infoShowed + osascript -e 'tell app "Sequel Pro" to display dialog "This command will send the SQL statement(s) - unencrypted - to an online service (http://www.dpriver.com). Please consider this before sending confidential data!\n\nThis message will only be displayed once." with icon caution' 2> 1 + if [ `cat 1 | wc -c` -ne 0 ]; then + rm -f 1 + exit $SP_BUNDLE_EXIT_NONE + fi + rm -f 1 +fi + +# send SQL to www.dpriver.com and replace the formatted SQL string in first responder; if a parser error occurred +# show error message and try to jump to the error +cat <<HTML +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> +<html> +<head> + <base href="http://www.dpriver.com/pp/"> + <title>Connecting www.dpriver.com</title> + <script> + function lookForResult() { + if(document.all.outputsql.value.length > 8) { + if(document.all.errorhint.style.display == "inline") { + var errormes = document.all.outputsql.value; + var re = /.*?\(\d+\s*,\s*(\d+)\).*/; + re.exec(errormes); + var pos = parseInt(RegExp.\$1) - 1; + re = /.*?(\d+).*/; + re.exec('$SP_SELECTED_TEXT_RANGE'); + var offset = parseInt(RegExp.\$1); + pos = pos + offset; + alert(document.all.outputsql.value); + window.system.setSelectedTextRange(pos+''); + } else { + var txt = document.all.outputsql.value; + var len = txt.length; + window.system.setSelectedTextRange('$SP_SELECTED_TEXT_RANGE'); + window.system.insertText(txt.slice(0,len-2)); + } + window.system.closeHTMLOutputWindow(); + } else { + setTimeout("lookForResult()",50); + } + } + + function waitForResult() { + window.system.suppressExceptionAlert(); + setTimeout("lookForResult()",50); + } + </script> + <script language="JavaScript" type="text/javascript" src="pp.js"></script> +</head> +<body onload='window.resizeTo(300,200);SQLFMT.format(document.all.sp_submit);waitForResult()'> +<div id="retvalues"></div> +<p><b>Copyright &copy; 2001-2010 Gudu Software<br>All Rights Reserved<br><a href="mailto:support@dpriver.com">Contact US</a></b></p> +<br><br><br><br><br> +<p align=right>Please wait…</p> +<div class="page-container-1" style="display:none;"> + <div id="container"> + <div id="wrapper"> + <div id="content"> + <form id="SqlFmtForm" name="frm_sqlformat" method="post" action="/cgi-bin/ppserver" onsubmit="return false;"> + <div id="secondpanel"> + <div id="sp_database"> + <label class="desc" style="display:inline;">Database</label> + <select name="dbvendor"> + <option value="mysql" selected>MySQL</option> + </select> + <label class="desc" style="display:inline;padding:0 0 0px 40px; border:0px solid;">Output:</label> + <select name="outputfmt"> + <option value="SQL" selected>SQL(Text)</option> + </select> + </div> + </div> + <div id="sqlpanel"> + <div id="sp_inputsql"> + <textarea id ="inputsql" name="inputsql" cols="1" rows="1" wrap="off"> + $SQL + </textarea> + </div> + <div id="sp_submit"> + <input type="button" id="btnformat" name="print" value="Format SQL" onclick="SQLFMT.format(this)" value="Format SQL"> + <label style="display:none;">(Time used: <span id="timestamp">0</span> seconds)</label> + </div> + <div id="sp_submit" style="text-align:left;"> + </div> + <label id="errorhint" class="desc" style="color:#DF0000 !important;display:none;"> + Can't format input sql, make sure there is no syntax error and select correct database. + <a href="" style="display:none;">OR Report a bug of this sql beautifier</a> + </label> + <iframe id="ioutputsql" ></iframe> + <div id="sp_outputsql" style="display:none;"> + <textarea id = "outputsql" name="outputsql" cols="80" rows="15" wrap="off" > + </textarea> + </div> + <div id="sp_errormsg" style="display:none;"> + Error message goes to here! + </div> + </div> + <div id="formatoptions"> + <select name="keywordcs"> + <option value="Uppercase" selected >Uppercase</option> + <option value="Lowercase" >Lowercase</option> + <option value="InitCap" >InitCap</option> + <option value="Unchanged" >Unchanged</option> + </select> + <select name="identifiercs"> + <option value="Uppercase" >Uppercase</option> + <option value="Lowercase" selected >Lowercase</option> + <option value="InitCap" >InitCap</option> + <option value="Unchanged" >Unchanged</option> + <option value="initcapeachword" >Init cap each word</option> + </select> + <select name="functioncs"> + <option value="Uppercase" >Uppercase</option> + <option value="Lowercase" >Lowercase</option> + <option value="InitCap" selected >InitCap</option> + <option value="Unchanged" >Unchanged</option> + </select> + <input type="radio" name="lnbrwithcomma" value="after" checked > After + <input type="radio" name="lnbrwithcomma" value="before" > Before + <input type="radio" name="lnbrwithcomma" value= "beforewithspace" > Before with space + <input type="radio" name="liststyle" value="stack" checked>Stacked + <input type="radio" name="liststyle" value="nostack">Not Stacked + <input type="radio" name="salign" value="sleft" checked> Align left + <input type="radio" name="salign" value="sright" > Align right + <input type="checkbox" name="andorunderwhere" value="yes" checked> And/Or under Where + <input type="checkbox" name="removelnbr" value="no" checked> Remove Linebreak before beautify + <input type="checkbox" name="trimquotechar" value="yes"> Trim Quoted Char of Each Line quoted char of eachline: <input type="text" name="quotechar" value= "&#34" size = 5 > + <input type="checkbox" name="compactmode" value="yes"> Compact the output of sql output + <input type="text" name="maxlenincm" value= "80" size = 5 > + </div> + <input type="hidden" name="clientid" value="4149-9094-8133-2031" /> + </form> + </div> + </div> + </div> +</div> + +</body> +</html> +HTML +</string> + <key>contact</key> + <string>znvy@ovovxb.qr</string> + <key>description</key> + <string>Send the current query or selection to www.dpriver.com and replace the current query or selection of the first responder by the server's formatted output. If a parser error occurred alert that error and tries to jump to the error location. + +Version 1.0</string> + <key>input</key> + <string>selectedtext</string> + <key>input_fallback</key> + <string>currentquery</string> + <key>internalKeyEquivalent</key> + <dict> + <key>characters</key> + <string>T</string> + <key>keyCode</key> + <integer>17</integer> + <key>modifierFlags</key> + <integer>1835008</integer> + </dict> + <key>keyEquivalent</key> + <string>^~@t</string> + <key>name</key> + <string>Format SQL</string> + <key>output</key> + <string>showashtml</string> + <key>scope</key> + <string>inputfield</string> + <key>tooltip</key> + <string>Send query or selection to www.dpriver.com to insert the SQL statement formatted</string> + <key>uuid</key> + <string>36E1F94D-D6C4-460A-A663-C694AF85E099</string> + <key>isDefaultBundle</key> + <true/> +</dict> +</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..39555369 --- /dev/null +++ b/SharedSupport/Default Bundles/Toggle JSON Format.spBundle/command.plist @@ -0,0 +1,72 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> +<dict> + <key>author</key> + <string>Hans-Jörg Bibiko</string> + <key>category</key> + <string>Format</string> + <key>command</key> + <string>DATA=$(cat) + +FORMAT=$(echo "$DATA" | head -n 1 | perl -e '$l=<>;if($l=~m/^\s*\{\s*$/) {print "1";} else {print "2";}') + +# if FORMAT == 1 then serialize JSON data otherwise pretty print them +if [ "$FORMAT" -eq "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)); + ') + if [ "$DATA" == "null" ]; then + echo "<font>An error occured while serializing JSON data!</font>" + exit $SP_BUNDLE_EXIT_SHOW_AS_HTML_TOOLTIP + fi + +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') + +printf "%b" "$DATA"</string> + <key>contact</key> + <string>znvy@ovovxb.qr</string> + <key>description</key> + <string>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</string> + <key>input</key> + <string>selectedtext</string> + <key>input_fallback</key> + <string>entirecontent</string> + <key>internalKeyEquivalent</key> + <dict> + <key>characters</key> + <string>J</string> + <key>keyCode</key> + <integer>38</integer> + <key>modifierFlags</key> + <integer>1572864</integer> + </dict> + <key>keyEquivalent</key> + <string>~@j</string> + <key>name</key> + <string>Toggle JSON Format</string> + <key>output</key> + <string>replaceselection</string> + <key>scope</key> + <string>inputfield</string> + <key>tooltip</key> + <string>Serialize or pretty print JSON data</string> + <key>uuid</key> + <string>87FD8A4F-90AA-4020-9E0B-8CDD05764D08</string> + <key>isDefaultBundle</key> + <true/> +</dict> +</plist> diff --git a/SharedSupport/Default Bundles/WrapInDelimiter.spBundle/command.plist b/SharedSupport/Default Bundles/WrapInDelimiter.spBundle/command.plist new file mode 100644 index 00000000..3588396e --- /dev/null +++ b/SharedSupport/Default Bundles/WrapInDelimiter.spBundle/command.plist @@ -0,0 +1,47 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> +<dict> + <key>author</key> + <string>Hans-Jörg Bibiko</string> + <key>category</key> + <string>Query Editor</string> + <key>command</key> + <string>echo "DELIMITER \${0:;;}" +echo "\${1:`cat`}\${1:\$0}" +echo "DELIMITER ;"</string> + <key>contact</key> + <string>znvy@ovovxb.qr</string> + <key>description</key> + <string>Wrap the current query or the selection in DELIMITER inserted as snippet to allow to modify the default delimiter ;; + +Version 1.0</string> + <key>input</key> + <string>selectedtext</string> + <key>input_fallback</key> + <string>currentquery</string> + <key>internalKeyEquivalent</key> + <dict> + <key>characters</key> + <string>W</string> + <key>keyCode</key> + <integer>13</integer> + <key>modifierFlags</key> + <integer>1835008</integer> + </dict> + <key>keyEquivalent</key> + <string>^~@w</string> + <key>name</key> + <string>Wrap query/selection in DELIMITER</string> + <key>output</key> + <string>insertassnippet</string> + <key>scope</key> + <string>inputfield</string> + <key>tooltip</key> + <string>Wrap the current query or selection in DELIMITER ;;</string> + <key>uuid</key> + <string>A67BDE10-0A76-45C2-98DB-B35AC731E8DA</string> + <key>isDefaultBundle</key> + <true/> +</dict> +</plist> |