Skip to content

rdavid/shellbase

Repository files navigation

Shellbase

             ,,                 ,,    ,,  ,,
           `7MM               `7MM  `7MM *MM
             MM                 MM    MM  MM
    ,pP"Ybd  MMpMMMb.  .gP"Ya   MM    MM  MM,dMMb.   ,6"Yb.  ,pP"Ybd  .gP"Ya
    8I   `"  MM    MM ,M'   Yb  MM    MM  MM    `Mb 8)   MM  8I   `" ,M'   Yb
    `YMMMa.  MM    MM 8M""""""  MM    MM  MM     M8  ,pm9MM  `YMMMa. 8M""""""
    L.   I8  MM    MM YM.    ,  MM    MM  MM.   ,M9 8M   MM  L.   I8 YM.    ,
    M9mmmP'.JMML  JMML.`Mbmmd'.JMML..JMML.P^YbmdP'  `Moo9^Yo.M9mmmP'  `Mbmmd'

text bsd text lnx test mac hits of code release license

About

The shellbase framework serves as a foundation for Unix shell scripts. The framework stays POSIX-compliant (Portable Operating System Interface for uniX) and runs across Unix-like systems. It offers essential services, including logging, validation helpers, signal handling, garbage collection, and support for concurrent instances.

Global variables have the BASE_ prefix. Clients may use them and should place temporary files under $BASE_WIP. All functions starting with the base_ prefix stay internal. Clients shouldn’t use them. Names appear in alphabetical order.

See dotfiles, gento, pulse, and toolbox as example projects that use this framework.

Install

The artifact consists of a single non-executable POSIX-compliant shell script file base.sh. Install the file from the repository:

git clone https://github.com/rdavid/shellbase.git &&
  ./shellbase/app/install

Install the file from a release. Some operating systems demand administrative rights to install to /usr/local/bin. Use sudo or doas before tar:

REL=0.9.20260404
SRC=https://github.com/rdavid/shellbase/archive/refs/tags/v$REL.tar.gz
curl --location --silent $SRC |
  tar \
    --directory /usr/local/bin \
    --extract \
    --gzip \
    --strip-components=2 \
    shellbase-$REL/lib/base.sh

Using

Verify /usr/local/bin appears in your PATH. Then your script can use shellbase:

#!/bin/sh
# shellcheck disable=SC1091 # File not following.
. base.sh
log I\'m using the shellbase.

You can try shellbase without installation:

#!/bin/sh
REL=0.9.20260404
SRC=https://github.com/rdavid/shellbase/archive/refs/tags/v$REL.tar.gz
eval "$(
  curl --location --silent $SRC |
    tar \
      --extract \
      --gzip \
      --to-stdout \
      shellbase-$REL/lib/base.sh
)"
log I\'m using the shellbase.

prettytable example:

. base.sh
{
  printf 'ID\tNAME\tTITLE\n'
  printf '123456789\tJohn Foo\tDirector\n'
  printf '12\tMike Bar\tEngineer\n'
} | prettytable

Output:

+-----------+----------+----------+
|ID         |NAME      |TITLE     |
+-----------+----------+----------+
|123456789  |John Foo  |Director  |
|12         |Mike Bar  |Engineer  |
+-----------+----------+----------+

Test

The project uses Daniel J. Bernstein’s build system, redo. You can install Sergey Matveev’s goredo implementation. redo lint applies the following linters to the source files: actionlint, checkmake, hadolint, reuse, shellcheck, shfmt, typos, vale, yamllint. redo test runs unit tests across installed shells. redo test-container runs the tests across various shells in containers. The project uses David Rabkin's goredoer to build goredo.

License

shellbase belongs to David Rabkin and uses a Zero-Clause BSD license.

About

The framework is specifically designed for Unix shell scripts.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors