Hologos / bashutils

Library of bash helper functions.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

bashutils

This library contains several helper functions to be used with bash.

Installation

Important: bash v3.2 and higher is required

Since this is a library, you should't use it alone. You should include it into your project. There are several aproaches:

Using peru

Peru is a tool for including others people's code into your projects.

You just define this dependency in peru.yaml:

imports:
    bashutils: vendor/hologos/bashutils/  # This is where we want peru to put the module.

git module bashutils:
    url: https://github.com/Hologos/bashutils.git

Save it and run:

peru sync

This will download the library and saves it into vendor/hologos/bashutils/.

Downloading the archive

  1. Download archive from the release page.
  2. Unpack it into vendor/hologos/bashutils/ in your project folder.

Cloning repo

Important: If you forget to do peru sync after every update that contained changed peru.yaml, it can have undesirable consequences and can cause serious problems. Use at your own risk.

git clone https://github.com/Hologos/bashutils vendor/hologos/bashutils/
peru sync

Loading the library

To include it in your project, just write:

source vendor/hologos/bashutils/bashutils

List of functions

bool bashutils::is_installed()
description Checks if program is callable.
void bashutils::terminate(message="")
description Terminates the program with optional message.
void bashutils::invoke_sudo()
description Requires user to enter his password for sudo.
string bashutils::basedir()
description Gets basedir of current script.
bool bashutils::is_macos()
description Checks if current os is macOS.
bool bashutils::is_linux()
description Checks if current os is from linux family.
bool bashutils::is_aix()
description Checks if current os is AIX.
string bashutils::get_os_family()
description Gets OS family name.
bool bashutils::is_min_bash_version(required-version)
description Checks if current bash version is equal or higher than required.
notes Format of required-version is maximum of 4 groups (numbers only) that are dot separated (eg: 4.2.2.1 or 4.4).
void bashutils::require_min_bash_version()
description Checks if current bash version is equal or higher than required. Terminates the script is it's not.

About

Library of bash helper functions.

License:MIT License


Languages

Language:Shell 100.0%