gumba
v1.0.1
Published
Gumba provides modern language features to your everyday shell scripting
Downloads
2
Readme
Gumba
Gumba 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:
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:
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:
First Example:
before Gumba:
echo ' IdentityFile "file_path"' | cut -d ' ' -f4 | tr -d '"'
after Gumba:
echo ' IdentityFile "file_path"' | u 'clean().words().last().trim("\"")'
Both return file_path
. So basically cut -d ' ' -f4 | tr -d
becomes
u '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.
Second Example — Sed replacement:
Another real world example comes from the question on StackOverflow — (How to trim whitespace?)[http://stackoverflow.com/questions/369758/how-to-trim-whitespace-from-bash-variable]
before Gumba:
echo ' test test test ' | sed -e 's/^ *//g' -e 's/ *$//g'
Seriously?
after Gumba:
echo ' test test test ' | u 'trim()'
More Examples:
Gumba uses just coffeescript so you can make regex replaces easily using standard javascript functions:
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:
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:
"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:
echo "Hello World" | u 'toUpperCase().take (line) -> "#{line}!"'
converts to javascript
"HelloWorld"
.toUpperCase()
.take(function(line){
return line + "!";
})
Contribute
Fork, Pull, Post Issues.
I would love to get any help in project cultivation.
:sunflower: