Giter VIP home page Giter VIP logo

lobash's Introduction

Lobash Logo

A modern, safe, powerful utility library for Bash script development.

TOC

What is Lobash?

Due to its complex syntaxes with symbols, and Unix commands are different in platforms such like BSD and GNU utilities have different options and behaviors with same command name, Bash script development is complex and fallible.

Javascript has a powerful library Lodash for simplifying development. So I build Lobash to do similar works for shell development.

Lobash is a library not a command. It provides collections of functions to improve efficiency of shell development, and make it compatible with Bash 4.0+ and MacOS/Linux/Alpine/Busybox systems.

Lobash Features

  • Modular and easy to use. One module one Function.
  • Rich Functions. Over 90+ modules provided.
  • Robust and Safe. Over 500+ test cases tested.
  • Fast. 0.058s to load Lobash completely.
  • Compatible with MacOS/Linux/Alpine/Busybox systems.
  • Compatible with Bash 4.0 and higher versions.

Build Status

ChangeLog

FAQ

Installation

Available Lobash versions refer to Git Tags which named like "vX.Y.Z".

VERSION=v0.3.1
# Download source codes
git clone --depth 1 --branch $VERSION https://github.com/adoyle-h/lobash.git
cd lobash
# This step is optional. Clone submodules only if you want to run test cases.
git submodule update --init --recursive

Prerequisites

Supported Platform

Supported Platform Version Main Reasons
MacOS * -
Linux * -
Busybox * -
Alpine * -
BSD - Not tested yet. Maybe not support.
🚫 Windows - Never and ever supported.

Supported Shells

Supported Shell Version Main Reasons
Bash v5 and higher Completely Supported
Bash v4.4 Completely Supported
✅💬 Bash v4.3 shopt -s inherit_errexit is not supported util v4.4
✅💬 Bash v4.2 Nameref is not supported util v4.3
✅💬 Bash v4.1 declare -g not support util v4.2
✅💬 Bash v4.0 exec {fd}<> <(true) is not supported util v4.1
🚫 Bash v3 Associative array is not supported until v4.0
🚫 POSIX sh * local keyword not supported
🚫 Zsh * Plan to implement it in another project
Ksh * No tested

✅💬 means Lobash can be used but not all features supported in shell. It prints notes to show what modules will be ignored when building Lobash file.

If you want use Lobash with Bash 4.3 and lower versions. Please read ./doc/with-lower-version-bash.md for details.

Lobash not test with Bash 4.0 in MacOS. It seems a bug of Bash 4.0 in MacOS. Please contact me if you solved this problem. See this document.

There is a list of which features were added to specific releases (versions) of Bash.

Although most Linux distributions use Bash v4.3, and MacOS not installed Bash v4 by default, it is easily to upgrade Bash 4.4+ in most systems.

Dependencies

Make sure below dependencies have been installed.

  • Linux commands:
    • sed/grep/mktemp/dirname/basename/cd/printf/echo/wc
    • sed: BSD and GNU are both supported

Usage

Build your lobash.bash

First, build your own lobash.bash file by ./build.

# Interactive build process
./build
# Generated Lobash file: <lobash-dir>/dist/lobash.bash

# Or build Lobash to specific path
./build <target-path>

See ./doc/build.md for more details.

Edit your scripts and set shell options

All Lobash modules are written and tested with the shell options:

  • set -o errexit
  • set -o nounset
  • set -o pipefail
  • shopt -s inherit_errexit

If you do not understand the meanings of these shell options, please read this article.

Lobash not enable these options by default. Make sure the same shell options enabled before call Lobash functions in your scripts. Otherwise there may be unexpected behaviors with it.

Load lobash.bash in your scripts

Second, load your own lobash.bash file in your scripts and all Lobash functions will be imported to current shell environment.

#!/usr/bin/env bash

set -o errexit
set -o nounset
set -o pipefail
(shopt -p inherit_errexit &>/dev/null) && shopt -s inherit_errexit

# It will load all Lobash modules
source <path-to-lobash.bash>
# Call l.<module_name> when build lobash.bash with default PREFIX
l.ask 'Hello Lobash?'

# Call lobash.<module_name> when build lobash.bash with PREFIX=lobash_
# lobash_ask 'Hello Lobash?'

Load lobash.bash is fast, nearly 0.058s in fact.

time source ./dist/lobash.bash

real    0m0.058s
user    0m0.022s
sys     0m0.036s

Module Usages

See all module usages in ./doc/module-usages/

Command

While Lobash is a library for development, it also provides a command ./bin/lobash.

Enter ./bin/lobash show help.

> ./bin/lobash

Usage:
  lobash [help|-h|--help]
  lobash mod <module_name> [<sub_command_args>]...
  lobash meta

Sub-Command:
  help       Show help
  mod        Invoke a Lobash module
  mods       Show available module names
  meta       Query metadatas of Lobash module
  github     Open Lobash github page in your browser

Description:
The "lobash mod" command is only used for certain scenarios. Many modules not work as command.

lobash meta

> ./bin/lobash meta normalize
Module: normalize
Usage: l.normalize <path>
Description:
  - Normalize the given path which can be an unexisted path.
  - Trailing `/` always be removed.
Dependent: split, join
Deprecated: false
Since: 0.1.0
Bash: 4.3
Status: tested

lobash mod

Note: The "lobash mod" command is only used for certain scenarios. Many modules not work as command.

> ./bin/lobash mod ask 'Is it OK?'
Is it OK? ([Y]es/No)
YES

Who use Lobash

Related Projects

References

Test

See ./doc/test.md for more details.

Contributions

Any suggestions and contributions are always welcome. Please open an issue to talk with me.

Please read ./doc/contribution.md before make a Pull Request.

Versioning

The versioning follows the rules of SemVer 2.0.0.

For more information on SemVer, please visit http://semver.org/ .

Copyright and License

Copyright 2019 ADoyle ([email protected]) Some Rights Reserved.

The project is licensed under the Apache License Version 2.0.

See the LICENSE file for the specific language governing permissions and limitations under the License.

See the NOTICE file distributed with this work for additional information regarding copyright ownership.

lobash's People

Contributors

adoyle-h 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.