• Stars
    star
    104
  • Rank 330,604 (Top 7 %)
  • Language
    Shell
  • License
    GNU General Publi...
  • Created almost 3 years ago
  • Updated over 1 year ago

Reviews

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

Repository Details

Bring bash to the next level

bash ++

This is a framework to bring bash to a next level.
Check out the examples ยป

Project status ยท Report Bug ยท Contribute code

Index

What is bash++ ?

Bash++ is a new way to bring bash to a next level. This framework introduces new functionalities to bash. Some of this functionalities are:

  • Unit testing
  • Classes
  • Imports
  • DotEnv
  • Logging
  • Types
  • Errors
  • and many more!

Bash++ is designed so that people could build more complex apps creating better products. Note that this project is for people with experience with bash (not much, just simple understandings and how things usually work).

When you run bash++ with bash, the application breaks. This is why you need to add #!/usr/bash to the start of the script (see instructions here).

Bash haves it's own module system, so you will have a bash++ folder in your /usr/libs directory (just so that you know).

(back to top)

Installation

To use bash++ you will (obviously) need to install it. To install it, clone the repo by running the following command:

git clone https://github.com/mauro-balades/bash-plusplus

After cloning the repository, cd into that directory. Once you are in the directory called bash++. Run the following command to proceed with the installation.

Note that you need to run it as root.

sudo make install

When you have installed it, you will see a new directory (usually in /usr/lib/bash++). This directory is where all of bash's built-in libraries will be stored.

Q/A

What's the point when python, perl and other more robust scripting languages exist?

This is something that comes up really often, I've found that Oil Shell main FAQ covers this topic thoroughly:

Be sure to check out Oil in more detail if you can, it's a very impressive project.

Usage

We all need to start somewhere, in this section you will se on how to use every functionality in bash++.

Getting started

To get started, create a bash script (or an existing one). Add the following shebang at the start of the file so that bash can know what file you use.

#!/bin/bash

After you have added the shebang, chmod the main script with:

chmod +x [SCRIPT_NAME].sh

Then, you can just simply run the script as:

./[SCRIPT_NAME].sh

NOTE: Replace [SCRIPT_NAME] with your main bash script.

(back to top)

Bootstrap the project

To bootstrap your script you will need to source the Import script in your libs folder.

. "${BASHPP_LIBS}/Import.sh" # Source bash++

NOTE: Only do this step once (aka in the main script). and you will need to put in at the top of the file.

(back to top)

Functionalities

Humans need help to learn something new, that is why in this section all bash++ functionalities will be explained with an example.

Import

Normal bash developers will use . or source to 'import' a bash script. Professional Bash++ developers will use the import function.

The Import function will let you choose more variation of sourcing methods that some developers will kill to have that. Apart from it giving more functionality it also creates new (or experienced) bash users a better syntax reading.

The following code is the function declaration for import:

# ImportService::Import (import)
#
# Usage:
#   import MyFile
#   import System # Builtin module
#   import github:mauro-balades/bash-plusplus
#   import https://example.com/script.sh
#   import script1 script2 ...
#
# Description:
#   This function is used to import your bash script.
#   The function is a replacement for "source" since
#   it contains more functionality and it makes the
#   code prettier
#
# Arguments:
#   [...any] scripts: Bash scripts to be imported
ImportService::Import() {
  ...
}

As you can see from the function declaration, import can be used in different ways such as:

  • Sourcing Files.
  • Sourcing Multiple Files.
  • Sourcing Urls.
  • Sourcing Github paths.
  • Sourcing Builtin modules.
  • And it adds a variation of bash scripts paths to check.

Description:

  • This function is used to import your bash script. The function is a replacement for "source" since it contains more functionality and it makes the code prettier

Usage:

  • import MyFile
    • checks for:
      • MyFile
      • $( pwd )/MyFile
      • $( pwd )/MyFile.sh
      • $( BASHPP_LIBS )/MyFile
      • $( BASHPP_LIBS )/MyFile.sh
      • /usr/lib/MyFile
      • /usr/lib/MyFile.sh
      • /opt/MyFile
      • /opt/MyFile.sh
      • /usr/share/MyFile
      • /usr/share/MyFile.sh
      • /usr/local/lib/MyFile
      • /usr/local/lib/MyFile.sh
      • $HOME/.local/lib/MyFile
      • $HOME/.local/lib/MyFile.sh
      • $HOME/.local/share/MyFile
      • $HOME/.local/share/MyFile.sh
  • import github:mauro-balades/bash-plusplus/...
    • Imports bash file from the raw.githubusercontent.com domain.
    • Notice how it starts with github:
  • import https://example.com/my/bash/script.sh
    • Sources a fetched file from an URL.
      • With curl
      • If curl does not exists, it will try with wget
  • import myfile1 myfile2 myfile3
    • Capable to source multiple files checking same files as the import MyFile example at the top. (each file is checked if it is a github URL a normal URL)

NOTE: It adds the script to an array of imported files. If you get an error saying that a file has already been sourced, remove that file from the import function since it already exists.

(back to top)

Import's extended API

Bash++ also exports some extra features from the import API.

alias import="ImportService::Import"

# Overrides
alias .="ImportService::SimpleImport"
alias source="ImportService::SimpleImport"

# Extending the API
alias import.url="ImportService::ImportUrl"
alias import.github="ImportService::ImportGitHub"
alias import.simple="ImportService::SimpleImport" # Same as source and .

# Utility functions
alias import.exists="ImportService::Exists"
alias import.nexists="ImportService::NExists"

alias import.addm="ImportService::AddModule"
  • . and source overridden with the ImportService.SimpleImport (import.simple) function. import.simple is basically the same as import except it does not support multiple files.
  • import.url and import.github are the functions used in import except for the import.github function you don't need the github: prefix. ( It does not support multiple files ).
  • import.exists and import.nexists this function returns a 1 if a module exists in the sourced files array. nexists returns 0 if it exists.
  • import.addm. This function takes a string as a parameter and adds that module to the array.
    • It does not source the file.

Feel free to check out the src/Import.sh file to see each function declaration (it's description, arguments and usage).

(back to top)

Classes

Classes are the main purpose of this project. To create a class, you will need to import a built-in module called Classes

# BOOTSTRAP ALREADY DONE ABOVE (IMAGINE)

import Classes

To define a class, it is like defining a normal variable except you have "attributes" inside it.

# BOOTSTRAP ALREADY DONE ABOVE (IMAGINE)

import Classes

MyClass=(

  function __new__ # When class is initiated
  function __delete__ # At the end of the script this is called

  function hello
  function hi = MyClass::different_function # If you call the function "hi", it will actually call MyClass::different_function

  declare name
) # Class called "MyClass"

Great, you have successfully declared a class (joke). To add functionality, how about declaring what the function will do. By the way, functions __new__ and __delete__ are completely optional.

# BOOTSTRAP ALREADY DONE ABOVE (IMAGINE)

import Classes

MyClass=(

  function __new__ # When class is initiated
  function __delete__ # At the end of the script this is called

  function hello
  function hi = MyClass::different_function # If you call the function "hi", it will actually call MyClass::different_function

  declare name
) # Class called "MyClass"

MyClass::__new__() {
  # Get the "self" value
  # Explained in the paragraph bellow.
  local self=$1
  shift

  echo "class has inited"

  # Set name to the first argument we get
  # NOTE that name is declared above
  # with the declare keyword
  #
  # "$1" was the self argument
  # but now, we shifter so that function
  # can hav arguments like a normal function
  $self.name= "$1"
}

MyClass::__delete__() {
  echo "Good Bye!"
}

MyClass::hello() {
  local self=$1
  shift

  NAME=$($self.name)
  echo "Hello, $NAME"
}

# Called with the "hi" function
MyClass::different_function() {
  local self=$1
  shift

  echo "Hi, $($self.name)"
}
  • the self argument. This argument is used for people to access class' variables. An example has been done above with the variable name. This argument is the first argument, so you can access it in $1

  • To declare a variable inside a class, you will need to declare with the declare keyword (you can declare an array using -a as an argument).

  • To change a variable's value, a function has been declared which is the following:

    $self.[VARIABLE_NAME]= "[VALUE]"
    

    Note that the = sign is not separated from the function name.

  • When user inits a class, arguments can be passed to the __new__ function. (and same with all functions)

(back to top)

Initiate a class

To create a new instance of a class, you will use the new function. In the new function, you need to add a class name, a new variable in which it is going to be created with that name and arguments that can be passed to the __new__ function.

Example (with context of the last example above):

#   | Class name     | Arguments passed to __new__ (can be infinite)
new MyClass my_class Rob
# ^         ^ new var to create with class instance

(back to top)

Call class' attributes

When you have created a new instance of a class, a variable is made so that you can access this functions and variables.

example:

$my_class.hello # arguments separated by spaces

and to access class' variables:

VAR=$($my_class.name)

(back to top)

.env

To import enviromental variables, you will need to include the dotenv module.

import dotenv

This will give you acces to the load_dotenv function. This functions has 1 optional parameter. That paramenter is the name of your .env file.

load_dotenv

# or
load_dotenv "path/to/.env"

(back to top)

License

# ================================ BASH ++ ================================
#
#    ...............................................
#    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#    @@@@@@@@@.(@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#    @@@@@@@      @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#    @@@@@@@@@      #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#    @@@@@@@@@@@       @@@@@@@@@@@@@@@@@@@@@@@@  @@@   @@
#    @@@@@@@@@@@@@      ,@@@@@@@@@@@@@@@@@@@@      @ @@@@@@
#    @@@@@@@@@@.      @@@@@@@@@@@@@@@@@@@@@@@@@  @@@   @@
#    @@@@@@@@      .@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#    @@@@@@@@    @@@@@@@@             #@@@@@@@@@@@@@
#    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&
#
# Copyright <Mauro Baladรฉs> 2021
# Bash++ Is under the license of "GNU GENERAL PUBLIC LICENSE
# =========================================================================

(back to top)

More Repositories

1

expross

Expross is a lightweight webserver to introduce JavaScript developers familiar with Express to Python.
Python
27
star
2

sf

A small system information fetcher.
Shell
11
star
3

secondssincelastjavascriptframework

Get the up to date information about how many seconds has passed since last javascript framework has been published.
HTML
11
star
4

ultimate-string-library

The ultimate string library for C where it's purpose is to eliminate the use of null terminators but allow C stdlib interactivity without the use of structs and still use char* arrays
C
6
star
5

NativeTS

A modern Typescript transpiler to llvm
TypeScript
4
star
6

www

My own portfolio!
TypeScript
4
star
7

brainfuck-plusplus

A brainfuck interpreter and compiler with some extra functionality.
Brainfuck
4
star
8

hello-world

hello-world in any programming language.
Assembly
3
star
9

r-shell

A shell made in rust
Rust
3
star
10

build-sys

A recreation from Makefile made in nim!
Nim
3
star
11

calculator

โž• a calculator interpreter in C
C
3
star
12

shaggy

Discover social media accounts across multiple platforms using just a username, the ultimate account hunting software.
Python
3
star
13

github-issue-templates

some issue templates for github issues
3
star
14

number-recognizer

Recognize numbers from an (28 x 28) image using neural networks
Python
3
star
15

generator-licenser

๐Ÿ“„ create a license with greate TUI
JavaScript
2
star
16

JS-2-Gera

๐Ÿ—ฟ Convert javascript files into Gera!
JavaScript
2
star
17

py-os

๐Ÿงช a 'fake' operating system to learn some CUI
C
2
star
18

PyTests

Write small or big tests with PyTests a (testing framework)
Python
2
star
19

breeze

Breeze is a light-weight, highly-customizable build tool for different languages such as C(++) and Java
Rust
2
star
20

is-url

A rust library to check if a string is an URL
Rust
2
star
21

townscaper-objects

my own townscaper builds and object files
2
star
22

3d-viewer

๐Ÿ—๏ธ View 3D objects in your terminal
Haskell
2
star
23

portofolio

Mi portofolio ๐ŸŽ‰
TypeScript
2
star
24

dotfiles

There is no place like ~/
CSS
2
star
25

os-fetch

Fetch information from your Linux distribution and computer.
C++
2
star
26

java-render

Render 3D objects in java
Java
2
star
27

aurora.css

A css preprocessor that allows you to write less and style more with an overall clear and beginner-friendly syntax
TypeScript
2
star
28

rn

Compile a simple programming language to node
Ruby
2
star
29

card-me

Create personal cards for your profile
JavaScript
2
star
30

mauro-balades

My own github profile!
Markdown
2
star
31

texor

Edit your files with syntax highlighing in the terminal
Rust
2
star
32

fortran-timer

โš—๏ธ I wanted to learn some fortran
Fortran
2
star
33

cpp-html-parser

A HTML tree generator library for C(PP)
C++
2
star
34

.github

๐ŸŒ The default files for my repos
YAML
2
star
35

sslb

๐Ÿ˜Š Super Simple Language Backend - An IR constructed language backend that can compile to various different targets, designed to be simple and safe.
Rust
2
star
36

craftingcompilers

A book I wrote to help and engage people into building their own compiler
Python
2
star
37

blib

(BLib: Better Library) A next generation C stdandard library replacement.
C
2
star
38

Confy

๐Ÿ’ป Configure projects effortlessly!
C++
2
star
39

debug-print

Write meaningful messages for debugging, supported in multiple languages
TypeScript
1
star
40

RTCM

RTCM is a tool to monitor command performance in real-time.
Shell
1
star
41

CodeQuest

๐Ÿ•ต๏ธโ€โ™‚๏ธ CodeQuest - Guess the Programming Language CLI Game
JavaScript
1
star
42

RetroByte

Minimalist, nostalgic, text-based OS.
Rust
1
star
43

maui

๐ŸŽจ Make your UI design dreams come true with MaUI! ๐Ÿš€
TypeScript
1
star
44

SnapKit

๐ŸŽจ Make your UI design dreams come true with SnapKit! ๐Ÿš€
TypeScript
1
star
45

gravity

Gravity browser - Privacy is not an option, it's a must
JavaScript
1
star
46

SimpleSQL

A simple SQL parser. It converts SQL statements into cpp objects for databases to use.
CMake
1
star
47

cclipboard

A multi-platform utility module to handle common tasks with the clipboard for C/C++
C++
1
star
48

yate

Yet another template engine. Yate is a small, fast html template engine.
Python
1
star
49

rect-dictionaries

Dictionaries support for the rect programming language
C++
1
star
50

gonzDB

GonzDB is a low-weight database for small projects.
Python
1
star
51

my-favorite-repos

โญ:octocat: A curated list of GitHub repositories I've starred!
1
star
52

CloneFish

Clone any website and convert it into a phishing website (Look at note in the readme)
Python
1
star
53

real-fake-updates

๐Ÿ•ถ๏ธ Fool your pals with super believable fake OS updates.
HTML
1
star
54

ChromeVaultExtract

a powerful software tool designed to effortlessly retrieve and extract saved passwords from the Google Chrome web browser.
Python
1
star
55

hands

A repository storing my assets
1
star
56

jbdb

This is a Json Based DataBase
Python
1
star
57

httplog

View a summary of your logs produced by your http server
C++
1
star
58

cursora

Create buautiful cursors for your website
TypeScript
1
star
59

py-include

Include python files on runtime.
Python
1
star
60

cdn-create

Create script/link tags to fetch your CDN resources and add them to your site at any time.
TypeScript
1
star
61

rect-isEven

Check if a number is even for the rect programming language
Rust
1
star
62

GitStatHub

โœจ Find statistics about your github repository and share them!
TypeScript
1
star
63

WhyIHateJS

A curated list containing things that will make you cry, re-evaluate about your decisions in life and feel disappointed at yourself for even trying JS
CSS
1
star
64

site-head

Create <head> tags for your website to focus on the website rather than the meta tags
JavaScript
1
star
65

color-tornado

Choose randomly generated colors with a user-friendly and interactive interface.
TypeScript
1
star
66

GarbleLang

An esoteric language to do some experiments with it
TypeScript
1
star
67

repository-generator

Generate your repositories in a markdown file in where you can use it as a github readme profile!
Python
1
star
68

pixel-perfect

Perfectly Designed, Pixel by Pixel
CSS
1
star
69

whoops-cpp

๐ŸŒŸ A growing collection of ulity classes and functions for common c++ tasks
C++
1
star
70

breeze-rect

A breeze plugin for the Rect programming language
Python
1
star
71

prompts-cpp

๐ŸŽจ A powerful C++ library designed to streamline the process of creating and managing beautiful prompts within your applications.
C++
1
star
72

img2ascii

Get ASCII art from your image
Rust
1
star
73

is-even

Checking if a number is even can get difficult sometimes. This repository contains different solutions for one problem. If you are questioning why this repository exists, please visit r/programmerhumor
JavaScript
1
star
74

GymBuddy

๐Ÿ‹๏ธ Track and share your fitness path with the rest of the world!
C++
1
star
75

Codex

Codex is a multi-platform IDE with intuitive and modern design.
JavaScript
1
star
76

password-judger

Does he bite? no, he judges you
TypeScript
1
star
77

FNAF-Resurgence

๐ŸŒŸ Five Nights at Freddy's: Resurgence โ€“ a hauntingly revamped FNAF remake bringing classic scares to a new level! ๐Ÿป๐ŸŒ™
1
star
78

auto-make

๐Ÿ“ฆ A new build tool that compilers bash script into makefile automatically
JavaScript
1
star
79

url-motion

Animate your browser url and make your website 1000 times more attractive.
TypeScript
1
star