All Projects → adoyle-h → Lobash

adoyle-h / Lobash

Licence: apache-2.0
A modern, safe, powerful utility library for Bash script development.

Programming Languages

shell
77523 projects
bash
514 projects

Projects that are alternatives of or similar to Lobash

oc-bootstrapper
Easily bootstrap a new October CMS project
Stars: ✭ 86 (-69.29%)
Mutual labels:  utility
go-tools
A utility tool library of Golang.
Stars: ✭ 44 (-84.29%)
Mutual labels:  utility
excel2xx
导出 Excel 到结构化数据或代码 ( lua, c/c++, go 等等由你的 mako 模板决定 )
Stars: ✭ 14 (-95%)
Mutual labels:  utility
proxy-pants
Secured and reliable Proxy based utilities for more or less common tasks.
Stars: ✭ 36 (-87.14%)
Mutual labels:  utility
powerlet
⚡️ Chrome Extension to quickly find and run bookmarklets
Stars: ✭ 17 (-93.93%)
Mutual labels:  utility
utility-ai
A small Utility Ai Framework
Stars: ✭ 16 (-94.29%)
Mutual labels:  utility
task-completed-checker-action
☑️ A GitHub action that checks if all tasks are completed in the pull requests.
Stars: ✭ 30 (-89.29%)
Mutual labels:  utility
Rationale
Ramda inspired library of helper functions for ReasonML
Stars: ✭ 275 (-1.79%)
Mutual labels:  utility
react-component-pack
Library that allows you to create context provider groups
Stars: ✭ 32 (-88.57%)
Mutual labels:  utility
thanosjs
Node.js implementation of Thanos JS website.
Stars: ✭ 34 (-87.86%)
Mutual labels:  utility
vimclip
Never type outside vim again
Stars: ✭ 70 (-75%)
Mutual labels:  utility
multipurpose-bot
a multipurpose discord bot made with dbd.js
Stars: ✭ 32 (-88.57%)
Mutual labels:  utility
tiny-zip
The missing Zip library for Java
Stars: ✭ 18 (-93.57%)
Mutual labels:  utility
ExecutionMaster
Windows utility for intercepting process creation and assigning standard actions to program startup
Stars: ✭ 54 (-80.71%)
Mutual labels:  utility
FSMon
File system monitoring utility written in plain PHP
Stars: ✭ 12 (-95.71%)
Mutual labels:  utility
SimpleCore
.NET C# common/utilities library
Stars: ✭ 11 (-96.07%)
Mutual labels:  utility
lpk
Find go projects/packages in your GOPATH
Stars: ✭ 13 (-95.36%)
Mutual labels:  utility
Eustia
Tool for generating utility libraries
Stars: ✭ 276 (-1.43%)
Mutual labels:  utility
vscode-snippet-generator
📜 Generate snippets from code in VSCode
Stars: ✭ 31 (-88.93%)
Mutual labels:  utility
glitter
Display git status information in your shell prompt
Stars: ✭ 47 (-83.21%)
Mutual labels:  utility

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 110+ modules provided.
  • Robust and Safe. Over 600+ 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

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 Descriptions
Bash v5 and higher Completely supported
Bash v4.4 Completely supported
✅💬 Bash v4.3 -
✅💬 Bash v4.2 -
✅💬 Bash v4.1 -
✅💬 Bash v4.0 -
🚫 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

Most Lobash modules support Bash 4.0+. See module usages to find what modules not compatible with Bash 4.0.

✅💬 means Lobash can be used but not all features supported in shell. It will print notes to show what modules is not supported and it 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 first.

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.

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

Installation

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

VERSION=v0.4.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 --progress

Usage

Build your lobash.bash

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

# Interactive build process, import all Lobash modules
./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
set -o errtrace  # You can remove this line if you do not use l.trap_error.
(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 available modules and categories in config.example.

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

See all module examples in ./example/modules.

Advanced Usages

Export specific modules with config

./build will export all modules by default. You can export specific modules with -c <config> option.

cp config.example config
# The "config" file is ignored by git

# Edit config, set PREFIX, BASH_MIN_VERSION and modules for building

./build -c ./config

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 <module_name>

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.0
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-2021 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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].