Skip to content

Instantly share code, notes, and snippets.

@tzmartin
Created November 5, 2013 01:31
Show Gist options
  • Save tzmartin/7312401 to your computer and use it in GitHub Desktop.
Save tzmartin/7312401 to your computer and use it in GitHub Desktop.
Run Javascript Textmate command
#!/usr/bin/env bash
. "$TM_SUPPORT_PATH/lib/webpreview.sh"
html_header "Javascript Runner" "Open Web Inspector for log"
YOURCODE=`cat`
cat <<HTML
<script>
(function(){try{
function e_sh(s){
return s
.toString()
.replace(/\x27/g,"’")
.replace(/\"/g,'\\\"')
;
};
window.alert = function(s){
TextMate.system('"$DIALOG" -e -p \'{messageTitle="JavaScript";informativeText="'+e_sh(s)+'";}\'', null);
};
var __TM_confirm_Status;
window.confirm = function(s){
TextMate.system('"$DIALOG" -e -p \'{messageTitle="JavaScript";informativeText="'+e_sh(s)+'";buttonTitles=("OK","Cancel");}\'', null)
.onreadoutput = function(s){ __TM_confirm_Status = s != 1; };
return(__TM_confirm_Status);
};
}catch(e){ console.log(e.message); }; })();
</script>
<pre id="log">
$YOURCODE
<script>
try{throw {}}catch(e){ window.__line=(e.line||0) + 3 };
try{
/*---- YOUR CODE ----*/
$YOURCODE
/*---- /YOUR CODE ----*/
}catch(e){
console.log(e);
var __line_offset = ${TM_INPUT_START_LINE:-1};
alert("$TM_FILEPATH:" + ((e.line||1) - __line + __line_offset) +"\n"+ e.message||'')
};
</script></pre>
HTML
html_footer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment