GithubHelp home page GithubHelp logo

bashplusplus's Introduction

BashPlusPlus

Bash with Class(es)

Initially this spawned from a friend having trouble formatting a string with color. At first I did a basic printf example, next came a little function that looked something like fmt.Println. After viewing their project I realized just how big of a script it was. It spanned multiple shell script files, had a number of functions, etc. After looking at it for a few minutes I thought...that could really use some classes.

Down the rabbit hole I went and emerged maybe more than a few hours later with this. It doesn't do a whole lot, really. But, it sure is fun to look at. :D

In all seriousness if you really want object oriented shell scripts have a look at korn shell 93.

Usage:

Download or clone this repository.

  • git clone
  • cd bashplusplus
  • Make sure bpp is executable chmod +x bpp
  • Add bpp to the PATH. export PATH=$PATH:$(pwd)/bin
  • Set an environment variable BPP_CLS_PATH that points to the classes directory.
  • export BPP_CLS_PATH=$(pwd)

Run an example:

  • cd examples
  • bpp hello.sh

A brief example

#hello.sh
include [fmt];

main() {
	fmt.Println "Hello, World";
}
$ bpp hello.sh
Hello, World

Documentation

Include

In order to use classes they need to be included in the script. It's possible to include builtin classes and to create and use local classes.

Builtin Classes

To include a builtin class the class name should be within square brackets:

include [fmt];

Local Classes

To include a local class the path and the class should be included within double quotes:

include "myclasses/myclass.sh"

Printing

Verbs

%% a literal percent sign; consumes no value %s the uninterpreted bytes of the string

function fmt.Printf

fmt.Printf(string, parameters)

fmt.Printf formats according to a format specifier and writes to standard output.

Example

include [fmt];

main() {
	name="Sam"
	fmt.Printf "Hello, %s!" name;
}

Output:

Hello, Sam!

function fmt.Println

fmt.Println(string)

fmt.Println accepts a formatted string and writes to standard output.

Example

include [fmt];

main() {
	fmt.Println "Hello, World";
}

function fmt.Errorln

fmt.Errorln(string)

fmt.Errorln accepts a formatted string and writes to standard error.

Example

include [fmt];

main() {
	fmt.Errorln "This is an error"
}

Strings (str)

function str.ToUpper

str.ToUpper(string) string

fmt.ToUpper returns s with all Unicode letters mapped to their upper case.

Example

include [fmt];
include [str];

main() {
	up=$(str.ToUpper "i'm lowercase")
	fmt.Println "${up}";
}

function str.ToLower

str.ToLower(string) string

fmt.ToLower returns s with all Unicode letters mapped to their lower case.

Example

include [fmt];
include [str];

main() {
	low=$(str.ToLower "I'M UPPERCASE");
	fmt.Println "${low}";
}

function str.Format

str.Format(string, parameters)

str.Format accepts a string with named formatting parameters and returns it fully formatted.

Parameters:

background color black red green brown blue purple cyan gray

effect underline blink

weight normal bold

Example

include [fmt];
include [str];

main() {
	fmt.Println "$(str.Format "hello, world" background "black" color "cyan" effect "underline" effect "blink" )"
}

bashplusplus's People

Contributors

bmcculley avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.