shell-api
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
- confirm
- export-file
- join-file
- pipe-file
- print-text
- read-file
- require
- start-daemon
- stop-daemon
- strict-mode
- terminate
- watch-daemon
- write-file
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>
...