Created
August 10, 2012 14:26
-
-
Save Teggy/3314596 to your computer and use it in GitHub Desktop.
Chocolat mixin: Replace selection with current date (example code that captures the output of a spawned process)
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
/*! | |
* Replace selection with current date | |
* Copyright(c) 2012 Torsten Grust <torsten.grust@gmail.com> | |
*/ | |
var spawn = require('child_process').spawn; | |
/** | |
* Hook up menu items. | |
*/ | |
Hooks.addMenuItem('Text/Insert/Current Date', 'control-shift-d', function() { | |
var date = spawn('/bin/date', []), | |
out = ''; | |
/* 'data' callback sends strings (not buffers) */ | |
date.stdout.setEncoding('utf8'); | |
date.stdout.on('data', function(data) { | |
out += data; | |
}); | |
date.on('exit', function(code) { | |
Recipe.run(function(recipe) { | |
var sel = recipe.selection; | |
recipe.replaceTextInRange(sel, out.trimRight()); | |
}); | |
}); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment