Git Product home page Git Product logo

bash-framework's Introduction

bash-framework

A collection of helper bash functions used to create lightweight and portable CLI wrappers for other tools.

Features

  • create portable bash scripts that follow a similar workflow and format
  • re-use helper functions across projects
  • write less boilerplate code and reduce duplication across projects (I'm looking at you, helper functions)
  • minimal runtime requirements
  • trackable/upgradable using a language agnostic tool (git)

Requirements

  • bash
  • readlink

Usage

This procedure describes the steps required for starting a Bash project that uses the framework.

Step 0. Set the framework version that you want to use

_FRAMEWORK_VERSION='0.8.0'

Step 1. Add the framework repository as a submodule in your bash script project/repo

cd my_bash_project
git submodule add [email protected]:adobe/bash-framework.git vendor/bash-framework     # get source code
git commit -m 'imported bash-framework as a submodule'                              # save submodule reference to top-level repo

Note: A hard copy would also work of course, but the git submodule approach enables clear framework version tracking and also provides an elegant upgrade workflow, without introducing any 3rd party tools besides git (which I assume you are already using).

Step 2. Pin the desired version

cd vendor/bash-framework
git checkout ${_FRAMEWORK_VERSION}
cd -
git add vendor/bash-framework
git commit -m "fixed bash framework version @ ${_FRAMEWORK_VERSION}"

Step 3. Import framework into your code

### Platform check
###############################################################################
unameOut="$(uname -s)"
case "${unameOut}" in
    Linux*)     machine=Linux;;
    Darwin*)    machine=Mac;;
    *)          machine="UNKNOWN:${unameOut}"
esac

### Binary set
###############################################################################
case "${machine}" in
    Linux*)     BIN_READLINK="readlink";;
    Mac*)       BIN_READLINK="greadlink";;
    *)          BIN_READLINK="readlink";;
esac

### Framework boilerplate
###############################################################################
# calculate script root dir
ROOT_DIR="$( dirname $(${BIN_READLINK} -f ${BASH_SOURCE[0]}) )"

# import bash framework
source "${ROOT_DIR}/vendor/bash-framework/lib/import.sh"

Step 4. Use the basic functionality

Please refer to the examples folder for functional demos of this library.

bash-framework's People

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

ghas-results

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.