Skip to content

codeforester/base-bash-libs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

base-bash-libs

Reusable Bash libraries extracted from Base.

This repository provides sourceable Bash libraries for scripts that want Base's logging, command execution, filesystem, and Git helper conventions without adopting the full Base workspace control plane.

Libraries

  • lib/bash/std/lib_std.sh Foundation helpers for logging, error handling, command execution, PATH updates, assertions, prompts, and imports.
  • lib/bash/file/lib_file.sh File editing helpers built on the stdlib.
  • lib/bash/git/lib_git.sh Git helper functions built on the stdlib.

Installation and Usage

Homebrew

Install the library package from the Base Homebrew tap:

brew trust codeforester/base
brew install codeforester/base/base-bash-libs

The trust step is required on Homebrew versions that block formulae from non-official taps until the tap is trusted. It is safe to run again on machines that already trust codeforester/base.

Source the installed stdlib from the Homebrew prefix:

base_bash_libs_prefix="$(brew --prefix codeforester/base/base-bash-libs)"
source "$base_bash_libs_prefix/libexec/lib/bash/std/lib_std.sh"
printf 'base-bash-libs version: %s\n' "$BASE_BASH_LIBS_VERSION"

Source Checkout

You can use a git checkout, tarball extract, or copied source tree without Homebrew. Keep the repository layout intact so lib_std.sh can find the root VERSION file:

git clone https://github.com/codeforester/base-bash-libs.git vendor/base-bash-libs

Source the stdlib from that checkout:

base_bash_libs_dir="$PWD/vendor/base-bash-libs"
source "$base_bash_libs_dir/lib/bash/std/lib_std.sh"
printf 'base-bash-libs version: %s\n' "$BASE_BASH_LIBS_VERSION"

Load companion libraries with absolute imports from the same checkout:

import "$base_bash_libs_dir/lib/bash/file/lib_file.sh"
import "$base_bash_libs_dir/lib/bash/git/lib_git.sh"

Vendored or Submodule Layout

For projects that vendor dependencies or use git submodules, place this repository anywhere stable inside your project and source it by absolute path:

project_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)"
base_bash_libs_dir="$project_root/vendor/base-bash-libs"

source "$base_bash_libs_dir/lib/bash/std/lib_std.sh"
import "$base_bash_libs_dir/lib/bash/file/lib_file.sh"
import "$base_bash_libs_dir/lib/bash/git/lib_git.sh"

After lib_std.sh is sourced, BASE_BASH_LIBS_VERSION contains the package version from the repository/package VERSION file. Downstream scripts can use that readonly constant when they need to require a minimum library version.

See examples/std-usage.sh for a small standalone script that sources the stdlib, imports the file helpers, logs progress, and runs a checked command.

Validation

Run the full local validation suite:

./tests/validate.sh

The suite expects bats and shellcheck to be installed. On macOS:

brew install bats-core shellcheck

Base

This repository is managed by Base. Base is useful for developing this repository, but it is not required to consume the Bash libraries from Homebrew, a source checkout, a vendored copy, or a git submodule.

Common commands:

basectl setup base-bash-libs
basectl check base-bash-libs
basectl doctor base-bash-libs
basectl test base-bash-libs

About

Reusable Bash libraries from Base

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages