Git Product home page Git Product logo

bashbox's Introduction

Introduction

Bashbox is a wannabe bash compiler which aims to help create modular and maintainable bash projects.

To give huge bash codebase a predictable form. Specially for the single script bash projects with thousands of lines of code.

Bashbox compiles your modular bash project into a single file along bringing a standard set of bash enforcements to ensure that your code is safe and less error-prone while you code and test before publishing it in an production environment.

And hey, we finally have some sort of std library for bash too! Along the ability to create your own library and let others use it. We have a cool stack trace thingy too!

Bashbox design is cargo inspired but for the bash buddies, so I hope that tells the rest.

Getting Started

You can start developing on Gitpod right away! Just press the button below.

Open in Gitpod

Or simply run the following command to install bashbox in your local system:

curl --proto '=https' --tlsv1.2 -sSfL "https://git.io/Jc9bH" | bash -s selfinstall

Now you are all set for creating awesome bash projects with it:

bashbox new project-name

An example project

src/main.sh

use foo;

function main() {
	echo "Hello world";
	foo "bar";
}

src/foo.sh

function foo() {
	local _input="$1";
	echo "Hello my name is ${_input}";
}

You can run the project by:

bashbox run --release

If you want to pass some arguments:

bashbox run --release -- arg1 arg2 and-so-on

You can also execute run in build mode:

bashbox build --release --run -- arg1 arg2 and-so-on

Note: Don't pass --run in build command unless you want to auto-run it after compiling.

A simple example:

bashbox build --release

For more information try bashbox --help

Compiling bashbox

It's simple, just run ./bashbox build --release after cloning this repository and bashbox will compile itself.

More things to write, this is incomplete at the moment

Please note that this project is very experimental and needs more work.

Caveats

Don't do the followings

  • Masking error:
if test "$(some_command --arg)" == "something"; then {
	do_something;
} fi

# Here due to the if statement it's impossible in bash to automatically catch the error within "$(some_command --arg)" subshell, which is why we need to assign it separately.

Solution:

local _var_foo;
_var_foo="$(some_command --arg)";

if test "$_var_foo" == "something"; then {
	do_something;
} fi
  • Undefined default variable in substitution:
local _argv="${1}"; # Can fail # Imagine the user never passed any argument and thus undefined by nature.

local _name_var="${SOME_ENV_VARIABLE}"; # Can fail # You're assuming that some environment variable is available but it might not be and thus undefined.

Solution:

local _argv="${1:-}";

local _name_var="${SOME_ENV_VARIABLE:-}";

# We declare a one-time default value which is empty incase the variable was never defined just to make our program run. Later for safety all you should do is test whether your variable is empty or contains some data.

bashbox's People

Contributors

axonasif avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

axonasif shism2

bashbox's Issues

Build multiple targets with shared code.

Hi! Thanks for this nifty little project!

I really like the idea. Suppose I have two scripts that use a common "library", foo.sh bar.sh and library called util.sh.

Build both by creating two project and linking util.sh from one place to another does not work, also relative use ../bla/src/util.sh does not work.

What works:

$ cat src/main.sh
use util/foo;

function main() {
        echo "Hello world";
}

Whre util is a git submodule I can sync to both projects. However, this really not trivial, and It would be cool if I could specify the main entry point for multiple "binaries" like with go for example.

As for example here. Obiviously, there will be a need to change the format of Bashbox.meta.

I hope my idea is clear. I'd love to contribute with some guidance.

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.