From: Mike Frysinger Date: Thu, 23 Oct 2014 04:07:55 +0000 (-0400) Subject: bash-colors: improve it X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=412ff3c0079915822df8ea5e79acd2c0d81bbeff;p=home.git bash-colors: improve it --- diff --git a/.bin/bash-colors b/.bin/bash-colors index 5474f9b..820958b 100755 --- a/.bin/bash-colors +++ b/.bin/bash-colors @@ -1,7 +1,8 @@ #!/bin/bash +# Author: Mike Frysinger ; released into the public domain; suck it. -if [[ $1 == "--env" ]] ; then - colors=( +show_env() { + local c colors=( GOOD="\$'\e[32;01m'" WARN="\$'\e[33;01m'" BAD="\$'\e[31;01m'" @@ -13,35 +14,64 @@ if [[ $1 == "--env" ]] ; then [[ -t 0 ]] || c="${c%=*}=" echo "${c}" done +} - exit 0 -fi +check256() { + if [[ ${TERM} != *-256color ]] ; then + ( + echo "warning: TERM (${TERM}) does not end in '-256color';" + echo "warning: trying to use 256 colors might not work." + ) >&2 + fi +} showit() { echo -e '\e['"${1};${2}mthis color is: \\\\e[${1};${2}m \e[0m" } -case $1 in -""|16|system) - for i in {0..1} ; do - for j in {30..37} ; do - showit ${i} ${j} + +main() { + case $1 in + --env) + show_env + ;; + ""|16|system) + for i in {0..1} ; do + for j in {30..37} ; do + showit ${i} ${j} + done done - done - ;; -cube|6x6x6) - for n in {16..231} ; do - showit "38;05" $(printf '%03i' ${n}) - done - ;; -gr[ae]y) - for n in {232..255} ; do - showit "38;05" ${n} - done - ;; -all|256) - for x in system cube gray ; do - echo "### SET: ${x}" - "$0" ${x} - done - ;; -esac + ;; + cube|6x6x6) + check256 + for n in {16..231} ; do + showit "38;05" $(printf '%03i' ${n}) + done + ;; + gr[ae]y) + check256 + for n in {232..255} ; do + showit "38;05" ${n} + done + ;; + all|256) + for x in system cube gray ; do + echo "### SET: ${x}" + "$0" ${x} + done + ;; + *) + cat <<-EOF + usage: $0 [colors] + + Colors: + - --env - show env you can eval in a shell + - 16, system - show basic colors (default) + - cube, 6x6x6 - show most extended colors + - gray - show gray scale + - all, 256 - show all colors + EOF + exit 1 + ;; + esac +} +main "$@"