Skip to content

biapy/biapy-bashlings

Repository files navigation

Biapy Bashlings

linting tests coverage CodeFactor

A bash functions library.

Bashlings are bash functions to be sourced in bash scripts. These functions are a hold-out from earlier times, and should be a last resort. Prefer using tools provided by a real bash framework.

Functions

  • available-fd : Find first unused file descriptor (fd) (for bash < 4.1 (e.g. macOS)).
  • cecho : Colored Echo: output text in color.
  • check-binary : Check for the presence of a binary in $PATH.
  • download : Download content from a URL and write it to /dev/stdout.
  • in-list : Test if a value is in a list.
  • is-array : Test if a variable is an array.
  • is-url : Test if a string is a HTTP, HTTPS, FTP or FILE URL.
  • join-array : Join an array contents with a string separator.
  • process-options : Alternative getopt for functions.
  • realpath-check : Resolve the real absolute path and check for its existence.
  • realpath : Resolve the real absolute path.
  • repeat-string : Repeat a string N times.

Usage

Import Biapy Bashlings in the project:

git submodule add \
  'https://github.com/biapy/biapy-bashlings.git' \
  'lib/biapy-bashlings'

See Cloning for including submodules when cloning a repository.

Make use of a Biapy Bashlings' function (e.g. in-list) in a script stored in src folder:

source "${BASH_SOURCE[0]%/*}/../lib/biapy-bashlings/src/in-list.bash"

in-list "${value}" "${example_list[@]}" && echo "Found."

Script skeleton

skeleton.bash is a skeleton of bash script implementation. It includes option processing, --quiet and --verbose implementation examples, and basic error messages.

Bash resources

  • Bash Reference Manual: The reference for Bash syntax and functionalities.
  • Bash FAQ: Frequently Asked Questions about Bash. This is a very good reference full of examples and recommendations.
  • ShellCheck: ShellCheck is a shell script analysis tool. It provides recommendations on good coding practices and alert of shell scripts' pitfalls.
  • shfmt: shfmt is a code formatter for shell scripts.
  • Bash-it: Bash-it is a Oh My Zsh inspired collection of Bash commands and scripts for Bash 3.2+.

Awesome lists for bash:

Package managers for publishing bash scripts:

Other interesting resources:

Third party libraries

Biapy Bashlings uses:

Biapy Bashlings uses these GitHub actions for Continuous Integration:

Contributing

Git

Cloning

This library uses the bats library for unit-testing.

Clone the repository with the additional libraries:

git clone --recurse-submodules 'git@github.com:biapy/biapy-downloader'

Updating submodules

Update the submodules with:

git submodule update --remote

Utilities

The Makefile provides these rules:

  • help : Display a short help message about the rules available in the Makefile.
  • clean : Delete generated documentation in doc/ and remove functions list from README.md.
  • format : format files using shfmt on *.bash files in src/ and *.bats files in test/.
  • check : check files for errors using shellcheck on *.bash files in src/.
  • test : run unit tests.
  • doc : Generate documentation in doc/ using shdoc.
  • readme : Update function list in README.md.
  • all : All of the above.

Thanks