Skip to content

web3promax/bash_colors

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 

Repository files navigation

Bash colors

The library defines verbal constants for ANSII color codes. Now you can use words to tell bash what color you want to use for output.

Also, it defines functions to quickly output colored text. As well as a function to display nice table of all colors.

Updated to allow for iterative output of colors by sequencing the color functions

Examples

Print "foobar" with red foreground:

$ clr_red "foobar"

Print "foobar" with green background:

$ clr_greenb "foobar"

Print "foobar" with cyan foreground and bold font:

$ clr_bold clr_cyan "foobar"

Stack functions on a single output to produce complex color configurations:

$ clr_red clr_blueb clr_reverse clr_underscore "foobar"

Using the -n switch, the output can remain on a single line, allowing for changing colors across a line of text:

$ clr_redb clr_black "RED" -n; clr_blueb clr_black "BLUE" -n; clr_greenb clr_black "GREEN";

or Print "foobar" manually, using variables:

$ clr_escape "foobar" $CLR_BOLD $CLR_CYAN

or any other code:

$ clr_escape "foobar" 1 36

Quick start

  1. Download source
$ curl https://raw.githubusercontent.com/mercuriev/bash_colors/master/bash_colors.sh > .bash_colors
  1. Load into your script
$ source .bash_colors

Variables

$CLR_*

Variables for each supported color code. E.g. $CLR_WHITE, $CLR_BLACK Call clr_dump for full list.

$CLR_ESC is a special variable for escape code (\033) followed by [ character.

Functions

clr_dump Output table of available colors, functions and variables.

clr_* string Functions for each supported color. E.g. clr_white, clr_black See clr_dump for list.

fn_exists General bash function to check if string is a valid function

clr_layer Recursive function allowing for muliple color functions in a sequence

clr_escape string $CLR ... escape string with given colors. Latest colors overwrites previous.

clr_reset Reset formatting. Useful for custom usage of $CLR_* variable series.

See also

console_codes(4) Advanced Bash Scripting Guide

About

The library defines verbal constants and functions for terminal colors.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages