Created
November 2, 2011 00:52
-
-
Save chjj/1332513 to your computer and use it in GitHub Desktop.
node functions for .bashrc
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
| # $ echo "console.log('hello world')" | runjs | |
| runjs() { | |
| cat | xargs -0 node -e | |
| } | |
| # usage: | |
| # $ echo "hello world" | jsrx "/h\w+/g" "hi" | |
| jsrx() { | |
| local str=$(cat | sed "s/\\\/\\\\\\\/g" \ | |
| | sed "s/'/\\\'/g" | sed ':a;N;$!ba;s/\r\n\|\n/\\n/g') | |
| local pat="$1" | |
| local sub="$2" | |
| echo "process.stdout.write('${str}'.replace(${pat}, '${sub}') + '\n')" | runjs | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment