A bash utility to add JavaScript code to a pipe. Requires node.
- Clone the repo:
git clone https://github.com/drewhodson/jipe.git
- Cd into the directory:
cd jipe
- Copy jipe to your bin directory:
cp jipe ~/bin/
The stringified content of stdin is stored in a variable called _
. Pass any JavaScript code as an argument to jipe.
echo 'hello world!' | jipe 'console.log(_.length)' # returns "13"
echo '{ "json": { "data": "hello!" } }' | jipe 'console.log(JSON.parse(_).json.data)' # returns "hello!"
To increase the terseness of scripts, the following aliases exist:
console.log
aliases:log
,l
process.stdout.write
aliases:write
,w
- Cast to string and print with newline:
print
,p
- Cast to string and print without newline:
output
,o
- Full contents of stdin:
__
- Full contents of stdin without trailing newline:
_n
For those of you familiar with AWK, or those who want a quick way to iterate over the lines of a file, use the flag -l
or --linewise
when invoking jipe to have the _
variable instead refer to each line of the file.
printf "hello\nworld\n.\n" | jipe -l 'p(_.length)' # returns 5\n5\n1\n
Unit tests written with bats.
Run tests with
bats test.bats
- Add man page
- What if I don't want colors in my output?
- Only
console.log
provides syntax highlighting, which is useful if you're printing JSON. However, useprint
oroutput
to avoid color codes being printed.
- Only