wdbashfunctions my Bash extra's for coloring, help, installation
doc generated from the script with gendoc
bash script, version=1.06

Synopsis

source wdbashfunctions
for use in scripts or ~/.bashrc
wdbashfunctions -[h|H|V]
for help on the command line

Options

-h
print short help and exit
-H
display full documentation with less and exit
-V
print version and exit

Description

wdbashfunctions defines functions and environment variables which I use in many, if not all, of my Bash scripts. It is meant to be sourced in ~/.bashrc.

Color functions

There are 32 3-letter commands which print their arguments, each on a new line, in color. The commands Bla, Red, Gre, Yel, Blu, Mag, Cya, and Whi print their arguments, separated with newlines, in black, red, yellow, blue, magenta, cyan and white respectively. The same commands with their second character capitalized print the same colors in a lighter variant. By capitalizing the third character, the arguments are printed in bold face. By captializing all characters, the arguments are printed in bold face in the light color variant.

If the first argument is on, a second 3-letter argument is expected which specifies the background color. Capitalizing the third (bold face) character has no significance here of course. Instead, it will cause the argument to blink.

In short:

  Red -> red
  REd -> light red
  RED -> light bold red
  Red on Yel -> red on yellow
  Red on YEl -> red on light yellow
  Red on YEL -> blinking red on light yellow
  RED on YeL -> blinking light bold red on yellow

Color variables

For each of the color functions, an environment variable with the same name is defined and exported. You use these when you want to different colors in the same string. For example, the following prints several color names, each in their own color:

   echo $Red red $REd light red $RED bold light red $BlU bold blue

Utility functions

die

prints its arguments in light red to standard error, each on a new line, and exits.

Warn

prints its arguments in magenta, each on a new line, to standard error.

warn

prints its arguments in magenta, each on a new line, to standard error, but only if $verbose is defined and has the value true.

helpsrt

prints short help for the script

helpall

prints full documentation of the script

instscr

installs the script in $PREFIX/bin, with html documentation in $PREFIX/bin/html and a man page in $PREFIX/bin/man/man1. This function is not for use by normal users, the administrator call it via the undocumented -I option. It needs two other scripts: instscript and gendoc.

docolor

Enable coloring; this is the default.

nocolor

Disable all coloring. Sets all coloring escape sequences to the empty string.

Author

Wybo Dekker

Copyright

Released under the GNU General Public License