shell-api

A robust set of POSIX-compliant scripts for shell environments


Keywords
posix, api, shell, script, ash, bash, dash, ksh, mksh, zsh
License
MIT
Install
npm install shell-api@1.1.0

Documentation

shell-api

Build Status NPM version GitHub version

Overview

A robust set of POSIX-compliant scripts for shell environments.

Shell support

The goal is to provide a simple API that is compatible with Bourne-like shells on *nix systems.

All functions have been tested in bash, dash, fish, ksh, and zsh.

The API


Getting started

Install

  • Install this project via npm.

    npm i shell-api --save
    
  • Symlink the shell directory within a project.

    ln -s ./node_modules/shell-api/shell ./.shell
    

Usage

Method A

#!/usr/bin/env sh

script_path=$(cd "$(dirname "${0}")"; pwd)
shell_api_path="${script_path}/../.shell"

# Load the whole framework at once
. "${shell_api_path}"/shell-api

export-file ./.env
require <SCRIPT>

...

Method B

#!/usr/bin/env sh

script_path=$(cd "$(dirname "${0}")"; pwd)
shell_api_path="${script_path}/../.shell"

# Selectively load parts of the framework
. "${shell_api_path}"/strict-mode
. "${shell_api_path}"/export-file
. "${shell_api_path}"/require

export-file ./.env
require <SCRIPT>

...