• Stars
    star
    192
  • Rank 202,019 (Top 4 %)
  • Language
    Shell
  • License
    GNU General Publi...
  • Created about 14 years ago
  • Updated over 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Object-oriented-like Bash framework

Skull

Skull is a Bash framework that provides an object-oriented-like interface for writing shell scripts or working on the terminal.

Skull is written purely in Bash and doesn't have any special requirements. Just drop, include and use.

Why?

Bash is awesome for many many things, but some tasks can be quite a pain to accomplish. Unlike most of the stuff you can do in Ruby/Python/etc by calling a method on an object, shell scripts usually require you to pipe here and back again -- which is not bad a bad thing, anyway --, like when you try to getting your system's IP address from ifconfig.

Besides, there is usually stuff that works differently in Mac than Linux, mostly because of the difference between the GNU and BSD variants of commands. And don't get me started on Windows. :)

Skull provides a unified interface for working with strings, arrays, hashes, processes, etc in Bash. You can also "instantiate" objects and work with them using an "object-like" interface.

Bash's syntax shares a couple of things with Ruby's, so I figured it wouldn't be too hard to make it look even closer. Take a look below.

Code

In Ruby you could work with an array like this:

>> a = Array.new
>> a.push 'foo'
>> a.count # => 1

Skull allows you to do pretty much the same, only without Ruby. Just plain ol' Bash.

$ Array.new a
$ a.push 'foo'
$ a.count # => 1
$ a.push 'bar'
$ a.find 'bar' # => 1 (second element)

Besides Array, there is Hash, String, Numeric, File and some other classes.

$ Hash.new h
$ h.store 'john' 'lennon'
$ h.get 'john' # => 'lennon'
$ h.all | while read key val; do echo "${key}: ${val}"; done # => 'john: lennon'

You can also call "class methods" directly, passing the element as an argument:

$ String.downcase "THIS ROCKS" # => "this rocks"
$ Process.kill 22674
$ File.size '/path/to/file.txt'

Yes sir, this is Bash.

How it works

Skull uses aliases as a way to attach "instance methods" to objects. So what Array.new is actually doing is associating a set of aliases and functions -- as declared by the Array "class" -- to the element passed.

How to use

Get a tarball or clone the repo:

$ git clone https://github.com/tomas/skull.git

If you want to use Skull in a script, just source the init script.

#!/bin/bash
. "/path/to/skull/init"
(your code)

Or use it directly from the command line. You can put in your ~/.bashrc and you'll have Skull 24/7.

. "/path/to/skull/init"

Now you can start playing around!

String.new str 'hello world'
str.length # => 11
str.titleize # => 'Hello World'
str.upcase # => 'HELLO WORLD'
str.sanitize # => 'hello-world'
str.urlencode # => 'hello%20world'
str.md5sum # => '5eb63bbbe01eeed093cb22bb8f5acdc3'

To get a list of available methods you can simply tab your way around or do:

str.methods # => capitalize contains downcase decrypt encrypt length (...)

Other useful stuff includes aliases, an Xml node parser or the System functions:

System.os # => linux
System.os.version # => 10.10
System.arch # => x64
System.logged_user # => god

Sending Pull Requests

  • Fork the project.
  • Make your feature addition or bug fix.
  • Add tests for it. This is important so I don't break it in a future version unintentionally.
  • Commit
  • Send me a pull request. Bonus points for topic branches.

Credits

Written by Tomás Pollak.

Copyright

Copyright (c) Fork Ltd. See LICENSE for details.

More Repositories

1

needle

Nimble, streamable HTTP client for Node.js. With proxy, iconv, cookie, deflate & multipart support.
JavaScript
1,597
star
2

jix

A better way to Git
140
star
3

network

The missing network utilities in Node.js.
JavaScript
113
star
4

dialog

Show native alert dialogs on Windows, OSX and Linux with Node.js.
JavaScript
55
star
5

bowtie

Simple admin interface for MongoMapper (mongo) & DataMapper (dm) models.
Ruby
50
star
6

tuktuk

Send emails with Ruby completely within your app. With DKIM too.
Ruby
19
star
7

satan

Bring daemons to life or destroy them forever. Cross platform, Node.js.
JavaScript
16
star
8

lisa

Lean deployment for single or multi-stage environments. Like Capistrano but in JS.
JavaScript
15
star
9

entrance

Lean, non-intrusive authentication for Rails and Sinatra, with out-of-the-box support for OAuth2.
Ruby
15
star
10

prey

REPOSITORY MOVED TO https://github.com/prey/prey-bash-client
15
star
11

spaghetti

Wrapper around GStreamer's gst-launch for Node.js.
JavaScript
12
star
12

wmic

Wrapper around the Windows WMIC interface for Node.js.
JavaScript
11
star
13

proxyconf

Node.js module for handling system proxy configuration. Unfinished.
JavaScript
9
star
14

dagger

Dagger.post(url, data).body -- Ruby HTTP Client
Ruby
9
star
15

reply

Node.js console-based wizards in a snap.
JavaScript
7
star
16

roster

Create or delete system user accounts in macOS, Linux and Windows.
JavaScript
6
star
17

linus

Get current Linux distro name and version, from Node.js.
JavaScript
5
star
18

pixelhopper

Animated GIF player for Linux (X11) and eventually macOS and Windows
C
5
star
19

tuna

Reverse tunnels for Node.js. Node.js for tunnels reverse.
JavaScript
5
star
20

tunable

Pluggable settings for your AR models.
Ruby
4
star
21

chela

Recursive, asynchronous chmod and chown for Node.js.
JavaScript
4
star
22

resizer

Paperclip image processor using Imlib2 instead of Imagemagick.
Ruby
4
star
23

buckle

Pure JS unzip that preserves file attributes.
JavaScript
4
star
24

memorize

Smart async function memoization. Node.js / Io.js.
JavaScript
3
star
25

ocelot

Spawn/exec with impersonation in Node.js.
Shell
3
star
26

getset

Smart configuration manager for Node.js client applications.
JavaScript
2
star
27

solidstate

Single-file state machine for Ruby. Yes, another one.
Ruby
2
star
28

angry_boss

Manage your pool of Delayed::Workers dynamically without mercy.
Ruby
2
star
29

remover

Stoppable recursive rmdir for Node.js.
JavaScript
2
star
30

whenever

Delayed require() of Node.js modules.
JavaScript
2
star
31

luaprompt

A nicer prompt for lua & luajit (forked from github.com/dpapavas/luaprompt)
C
2
star
32

sudoer

Wrapper around the sudo command for Node.js.
JavaScript
1
star
33

twin

Simple TCP-based Node.js IPC.
JavaScript
1
star
34

dimension

Simple, light image resizing in Ruby (with vips, imlib2 or ImageMagick)
Ruby
1
star