Bash Infinity Framework

 

Project Description

Bash Infinity is a standard library and a boilerplate framework for writing tools using bash. It’s modular and lightweight, while managing to implement some concepts from C#, Java or JavaScript into bash. The Infinity Framework is also plug & play: include it at the beginning of your existing script to import any of the individual features such as error handling, and start using other features gradually.

The aim of Bash Infinity is to maximize readability of bash scripts, minimize the amount of code repeat and create a central repository for well-written, and a well-tested standard library for bash.

Bash Infinity transforms the often obfuscated “bash syntax” to a cleaner, more modern syntax.

Disclaimer: Not all of the modules work with earlier versions of bash 3, as I test primarily with bash 4. However, it should be possible (and relatively easy) to port non-working parts to earlier versions.

Main features

  • automatic error handling with exceptions and visual stack traces (util/exception)
  • named parameters in functions (instead of $1, $2…) (util/namedParameters)
  • passing arrays and maps as parameters (util/variable)
  • try-catch implementation (util/tryCatch)
  • throwing custom exceptions (util/exception)
  • import keyword for clever sourcing of scripts à la require-js (oo-bootstrap)
  • handy aliases for colors and powerline characters to increase readability in the output of your scripts (UI/Color)
  • well-formatted, colorful logging to stderr or custom delegate functions (util/log)
  • unit test library (util/test)
  • standard library for the type system with plenty of useful functions (util/type)
  • operational chains for functional programming in bash (util/type)
  • type system for object-oriented scripting (util/class)

Most of the features are modular and it’s easy to simply use one of the features, e.g. the named parameters module is self-contained in one file.

For more information, please check out the GitHub repository for this project.

Functional and Object-oriented programming in bash?

As crazy as it may sound, the project implements a typing system and a class system. Believe it or not, but that definition in the picture above is in fact all valid Bash. There are other projects out there that aim to do the same, but they are not feature-complete, and the type definitions for most of them were ugly, at best. I wrote this as a part of an effort to rewrite SANEi to it’s next version, v2.0.

With Infinity Framework’s typing system, it becomes possible to write this kind of code in Bash.

 

Project Details

Date

January 2015

My involvement

the concept
programming
testing

Technologies

Bash
Linux Ubuntu Server

Website

GitHub

Get the source

MIT License.
Feel free to fork and contribute.

See other projects