Skip to content

Colors for POSIX compliant shell scripts without any dependencies or fuss

License

Notifications You must be signed in to change notification settings

MidnightRocket/posix-colors

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 

Repository files navigation

posix-colors

Colors for POSIX compliant shell scripts without any dependencies or fuss. Because it is POSIX compliant, all the shells are supported. E.g. Bash, Zsh, SH, Ksh and Dash.
Basic formatting such as bold and underline is also supported!

asciicast

The script automatically disables colors when output is NOT a terminal. E.g. when outputting to a file no weird escape sequences (\033[3m) is included. Conversely when outputting to the terminal, all those beautiful colors shine through! However this behaviour can be customised. See below

How to use

Tip

See example.sh for how to use.

You can either simply copy the contents of posix-colors into your script. Or you can download this repo and source the file like so:

. /path/to/posix-colors

Or for bash and zsh you alternatively use:

source /path/to/posix-colors

Controlling auto coloring

As mentioned above this script supports automatic coloring depending on whether or not output is a tty.
This means when viewing output from the script directly, colors will be displayed.
But when redirecting to a file or piping to other programs the color escape codes are automatically disabled. So you won't get those weird escape sequences.

It follows the standard proposed here: clicolors

That means if CLICOLOR_FORCE is set in the environment before the script is run or sourced, then the color escape sequences are always used. For instance seeing color with less:

CLICOLOR_FORCE=true ./example.sh | less -R

Conversely can color output be completely disabled regardless of tty by setting NO_COLOR env variable:

NO_COLOR=true ./example.sh

Resources

About

Colors for POSIX compliant shell scripts without any dependencies or fuss

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages