From 9738c24eff3ebb2689b2449cef3edd7ffc372a82 Mon Sep 17 00:00:00 2001 From: Thomas Lange Date: Sun, 24 Apr 2016 07:45:31 +0200 Subject: Initial commit --- Bash/ansi-color-output.sh | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100755 Bash/ansi-color-output.sh diff --git a/Bash/ansi-color-output.sh b/Bash/ansi-color-output.sh new file mode 100755 index 0000000..1bcff7c --- /dev/null +++ b/Bash/ansi-color-output.sh @@ -0,0 +1,41 @@ +#!/bin/bash +#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%# +# ANSI color output [Thomas Lange ] # +#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%# +# # +# This function uses ANSI escape sequences to output colored strings. See here # +# [https://en.wikipedia.org/wiki/ANSI_escape_code] for more information. # +# # +# Parameter 030: Black # +# Parameter 031: Red # +# Parameter 032: Green # +# Parameter 033: Brown # +# Parameter 034: Blue # +# Parameter 035: Purple # +# Parameter 036: Cyan # +# Parameter 037: Gray # +# Parameter 130: Dark Gray # +# Parameter 131: Light Red # +# Parameter 132: Light Green # +# Parameter 133: Yellow # +# Parameter 134: Light Blue # +# Parameter 135: Light Purple # +# Parameter 136: Light Cyan # +# Parameter 137: White # +# # +#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%# + +function color() { + case $1 in + 030)(printf '\033[0;30m%s\033[0m' $2);;130)(printf '\033[1;30m%s\033[0m' $2);; + 031)(printf '\033[0;31m%s\033[0m' $2);;131)(printf '\033[1;31m%s\033[0m' $2);; + 032)(printf '\033[0;32m%s\033[0m' $2);;132)(printf '\033[1;32m%s\033[0m' $2);; + 033)(printf '\033[0;33m%s\033[0m' $2);;133)(printf '\033[1;33m%s\033[0m' $2);; + 034)(printf '\033[0;34m%s\033[0m' $2);;134)(printf '\033[1;34m%s\033[0m' $2);; + 035)(printf '\033[0;35m%s\033[0m' $2);;135)(printf '\033[1;35m%s\033[0m' $2);; + 036)(printf '\033[0;36m%s\033[0m' $2);;136)(printf '\033[1;36m%s\033[0m' $2);; + 037)(printf '\033[0;37m%s\033[0m' $2);;137)(printf '\033[1;37m%s\033[0m' $2);; + esac +} + +echo "Example: $(color 134 "Hello World")!" \ No newline at end of file -- cgit v1.2.3