Gumba provides modern language features to your everyday shell scripting
npm install gumbaGumba likes to live between your shell pipes. When writing scripts is too much
hassle and writing shell function is too much magic you use Gumba.
Installation
------------
Make sure you have Node.js & npm installed.
You can install Gumba using npm command:
``shell`
npm install -g coffee-script
Also if you are going to using to use it frequently and I hope so, add a shorthand to your shell init file:
`shell`
alias u='gumba'
Usage
-----
With gumba you can use coffescript language powered by underscore & underscore.string inside your command line. Think of Gumba as a kind of awk or sed.
Look at following examples:
before Gumba:
`shell`
echo ' IdentityFile "file_path"' | cut -d ' ' -f4 | tr -d '"'
after Gumba:
`shell`
echo ' IdentityFile "file_path"' | u 'clean().words().last().trim("\"")'
Both return file_path. So basically cut -d ' ' -f4 | tr -d becomesu 'clean().words().last().trim("\"")'. Although first is not so bad,
the second still feels cleaner and easier to remember. This is a real
world example, after which I decided to make Gumba.
before Gumba:
`shell`
echo ' test test test ' | sed -e 's/^ //g' -e 's/ $//g'
Seriously?
after Gumba:
`shell`
echo ' test test test ' | u 'trim()'
Gumba uses just coffeescript so you can make regex replaces easily
using standard javascript functions:
`shell`
echo "['bulbasaur' 'chermander' 'pikachu'];" |
u "trim('[];')\ # -> 'bulbasaur' 'chermander' 'pikachu'
.replace(/'.*?'/g, (match) -> match.trim('\'').humanize())\ # -> Bulbasaur Chermander Pikachu
.words().toSentence()" # -> Bulbasaur, Chermander and Pikachu
Gumba provides take function which provides you ability to use
javascript in more flexible way using line object as it's argument:
`shell`
echo hi | u 'take (line) -> "#{line.toUpperCase()}!"' # -> HI!
Supported methods
-----------------
Gumba extends standard javascript object prototype with underscore &
underscore.string functions. For example on String object you can
use either underscore.string, underscore object or default javascript
methods:
`coffeescript`
"Hello World"
.toUpperCase() # standard javascript
.capitalize() # underscore.string
.isString() # underscore
To have a look on underscore methods reference go here,
for underscore.string — here
Function evaluation
-------------------
Every time you pipe to gumba it evaluates function passed as argument passed to to each line
of piped stream:
`shell`
echo "Hello World" | u 'toUpperCase().take (line) -> "#{line}!"'
converts to javascript
`coffeescript``
"HelloWorld"
.toUpperCase()
.take(function(line){
return line + "!";
})
Contribute
----------
Fork, Pull, Post Issues.
I would love to get any help in project cultivation.
:sunflower: