Created
June 22, 2017 10:14
-
-
Save geekdenz/f25b24476b00ebd988882cab3d5b17fd to your computer and use it in GitHub Desktop.
Pipe your shell programs through JavaScript.
This file contains hidden or 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
var readline = require('readline'); | |
var rl = readline.createInterface({ | |
input: process.stdin, | |
output: process.stdout, | |
terminal: false | |
}); | |
var f = process.argv[2]; | |
rl.on('line', function(line){ | |
var str = line.replace(/[\""]/g, '\\"'); | |
eval('('+f+')("'+str+'")'); | |
}); | |
// usage: command | node pipe.js "(line) => function_body" | |
// e.g. | |
// df -h | node pipe.js '(s)=>{let spl = s.split(/\s+/); console.log(spl[spl.length-1])}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment