Giter VIP home page Giter VIP logo

bashfox's Introduction

BashFOX

A small bash script builder/framework.

Installation

Using an install script (Recommended)

By this way, you will need Bash, cURL, Perl, and coreutils installed. You will not need Git.

curl -L https://github.com/romw314/bashfox/raw/master/install.bash | bash
. ~/.bashrc

Please note that the install script modifies your .bashrc, which means that you need to use . ~/.bashrc in order to use BashFOX.

Manually

This way you will need Git and coreutils installed.

git clone https://github.com/romw314/bashfox
cd bashfox
chmod 755 bashfox.bash
mkdir -p ~/.local/bin
cp bashfox.bash ~/.local/bin/bashfox

Please ensure that ~/.local/bin is in your path after manual installation.

Uninstallation

You will need Bash, cURL, Perl, and coreutils installed. You will not need Git. If you installed BashFOX with the install script uninstall it with:

curl -L https://github.com/romw314/bashfox/raw/master/uninstall.bash | bash

Elsewhere, simply remove the symlink from ~/.local/bin:

rm ~/.local/bin/bashfox

Usage

Write your code to .bash files. See the examples for more information.

Write your entry code to main.bash.

Write your configuration to bashfox.conf (see the examples).

Compile it using bashfox.

Example

src/main.bash

# It's important not to place comments on the same line
# as `import`, `debug`, `warn`, or any other BashFOX command.
# `import` imports a script without building it
# (useful for importing libraries that are already built, see lib/lib.bash)
import ../lib/lib.bash
debug  "This shows only if you use DEBUG=1"
notice "EXAMPLE notice"
info   "hello"
warn   "There is no useful code in this script"
if [ "$1" == "hello" ]; then
  fatal "The first argument shouldn't be 'hello'"
fi
# Include is the same as `import`, but builds the script.
# Script imported by `include` can contain BashFOX commands.
include extras/help.bash
error "Something went wrong"

src/extras/help.bash

# lib.bash is imported only once because of the _LIB_BASH variable.
import ../../lib/lib.bash

if [ "$1" == "help" ]; then
  info "USAGE:"
  info "$0 $(lib.wrap_in_brackets help) ..."
  info "Don't pass 'hello' to the first argument!"
  exit 0
fi

lib/lib.bash

# Here we can't use BashFOX commands.

if [ -z "$_LIB_BASH" ]; then
  # We don't export this, because we want to re-import the library
  # in scripts executed (not imported) from main.bash.
  _LIB_BASH=1

  # This library is named 'lib'.
  # We don't have namespaces in bash,
  # but we can declare functions with a dot.
  lib.wrap_in_brackets() {
    # Declare uses local variables unless -g is passed, so it is right here.
    declare result=''
    while (( "$#" )); do
      result="$result [$1]"
      shift
    done
    echo "${result:1}"
  }
fi

bashfox.conf

OUTPUT=outscript.bash # The output bash script
SOURCE=src            # The directory where main.bash is

Compilation and running

$ bashfox
BashFOX by romw314
SUCCESS
$ ./outscript.bash
[NOTICE] EXAMPLE notice
[ INFO ] hello
[ WARN ] There is no useful code in this script
[  ERR ] Something went wrong
$ ./outscript.bash hello
[NOTICE] EXAMPLE notice
[ INFO ] hello
[ WARN ] There is no useful code in this script
[ FATAL] The first argument shouldn't be 'hello'
$ ./outscript.bash help
[NOTICE] EXAMPLE notice
[ INFO ] hello
[ WARN ] There is no useful code in this script
[ INFO ] USAGE:
[ INFO ] ./outscript.bash [help] ...
[ INFO ] Don't pass 'hello' to the first argument!

bashfox's People

Contributors

romw314 avatar

Watchers

 avatar

bashfox's Issues

Send repo comments here

If you have a comment for this repo (example: I like it!), send it here.

But if you like this, consider adding a star. โญ

[BUG] Uses FATAL instead of INFO

Describe the bug
It logs [ FATAL] (but with correct color) when using the info command.

To Reproduce
Steps to reproduce the behavior:

  1. Compile and run the example script
  2. Output will contain [ FATAL] hello

Expected behavior
The output should contain [ INFO ] hello, not [ FATAL] hello.

System information (please complete the following information):

  • OS: Ubuntu
  • Version 22.04

Add multi-file and library support

Describe the solution you'd like
Add support for include (multi-file program) and import (import library from a directory or file).

Describe alternatives you've considered
No alternatives.

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.