A collection of lightweight bash utilities for command line programs. Each utility is designed as a reusable function that can be sourced into your scripts.
Add as a git submodule:
git submodule add https://github.com/username/script-utils.git utils
Source the utilities you need:
# shellcheck source=/dev/null
source 'utils/datetime/timestamp.sh'
source 'utils/strings/colors.sh'
timestamp.sh - Get current Unix timestamp
timestamp # Returns: 1640995200
fatal.sh - Print error message and exit
fatal "Something went wrong" # Prints red error and exits
script_location.sh - Get directory of current script
get_script_location # Returns: /path/to/script/directory
progress_bar.sh - Display progress bar
progress_bar 50 # Shows: 50% [████████████░░░░░░░░░░░░░]
progress_bar 75 30 # Custom width: 75% [██████████████████████░░░░░░░░]
colors.sh - Colored text output functions
red "Error message" # Red text
green "Success message" # Green text
yellow "Warning" # Yellow text
blue "Info" # Blue text
lowercase.sh - Convert text to lowercase
lowercase "HELLO" # "hello"
uppercase.sh - Convert text to uppercase
uppercase "hello" # "HELLO"
prefix.sh - Add prefix to each line in file
prefix file.txt # Adds " to start of each line
suffix.sh - Add suffix to each line in file
suffix file.txt # Adds " to end of each line
Tests are written using the bats testing framework. To test, run the following command (requires homebrew if bats is not installed):
make test