Skip to content

jharuda/bhf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bhf - BASH Helper Functions - Framework

This is a BASH lightweight framework with many useful functions. It main focus is to enable users to write programs with higher level of abstraction.

Some parts of this framework use more advanced features like using reference variables. Because of it, it requires BASH 4.3 or newer witch is not a big deal in this age.

Introduction

This framework consists of useful functions for:

  • Logging
  • Debugging
  • Interactive dialogs
  • Help with parsing arguments
  • Manipulation with strings
  • Manipulation with arrays
  • Files related operations
  • Error handling

You can read documentation in the file docs/bash_helper_functions.md and on your machine you can view PerlDoc documentation with bhf-help --only-view or by opening the file docs/bash_helper_functions.perldoc with perldoc command.

How to use - methods

1. Using the tool utils/bhf-init.sh

You can use this script to generate a whole new script from template. A new script will be placed in the current directory and will be linked with BHF.

First you need to load bhf_aliases.sh.

To do it, put the following to your ~/.bashrc:

export BHF_FRAMEWORK_PATH="/home/user/git/gitlab.cee.redhat.com/rhel-system-roles/automation-scripts/src/share/bhf"
. "${BHF_FRAMEWORK_PATH}/utils/bhf_aliases.sh"

Then you can start generating a new script with BHF skeleton included.

bhf-init --name new-bhf-script

The new script is linked to the BHF out of the box. The BHF_FULL_DIR_PATH environment variable contains path to the main BHF library src/bash_helper_functions.sh.

You can start immediately using the new program

bash new-bhf-script.sh

If you are more interested in how bhf-init works, you can read the documentation docs/bhf_init.md. The generated new script has the following default documentation that is described in docs/bhf_template.md.

2. Manual include

You can also easily include the BHF framework directly on the beggining of your existing script

#!/bin/bash

[[ "$0" != "${BASH_SOURCE[0]}" ]] && {
    echo "ERROR: This script can't be sourced"
    return 1
}

this_script_path="$(realpath "$0")"
this_script_dir="$(dirname $this_script_path)"
this_script_filename="$(basename $this_script_path)"

BHF_FULL_PATH="${BHF_FULL_PATH:-${this_script_dir}/share/bhf/src/bash_helper_functions.sh}"
export BHF_FULL_DIR_PATH="$( dirname "$BHF_FULL_PATH" )"

source "$BHF_FULL_PATH" || {
   echo "ERROR: Problem loading BHF framework"
   exit 2
}
bhf_print_debug "${this_script_filename}: the library 'BASH Helper Functions' - BHF succesfuly sourced"

...

Documentation

The main documentation is available in the file docs/bash_helper_functions.md. On your machine you can view PerlDoc documentation with bhf-help --only-view or by opening the file docs/bash_helper_functions.perldoc with perldoc command.

There are some commands with bhf- specialized on work with documentation.

This is wrapper around bhf-c2md, bhf-md2perldoc and perldoc commands.

It generates and displays documentation.

All parameters are available in the detail file docs/bhf_help.md

It generates Markdown file from shell comments in the shell script/library.

All parameters are available in the detail file docs/bhf_c2md.md

It generates perldoc file from Markdown. By default it loads and stores data to the directory /docs.

All parameters are available in the detail file docs/bbhf_md2perldoc.md

License

MIT

About

BASH Helper Functions - Framework. This is a BASH lightweight framework with many useful functions. Its main focus is to enable users to write programs with higher level of abstraction.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages